:root {
  color-scheme: light dark;
  --bg: #12141a;
  --surface: #1c1f28;
  --surface-hover: #262a36;
  --text: #f1f2f4;
  --text-muted: #9298a6;
  --accent: #5b8cff;
  --accent-active: #3ecf8e;
  --danger: #e5484d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
}

main {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 48px;
}

.tile {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tile-play-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 20px 12px;
  min-height: 84px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  word-break: break-word;
}

.tile-play-btn:active {
  transform: scale(0.97);
}

.tile:hover .tile-play-btn {
  background: var(--surface-hover);
}

.tile.playing .tile-play-btn {
  background: var(--accent-active);
  color: #04231a;
}

.tile-edit-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 10px;
}

.tile-edit-controls[hidden] {
  display: none;
}

.tile-rename-input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.tile-replace-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  cursor: pointer;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

.btn-icon {
  background: var(--surface);
  padding: 10px 12px;
  font-size: 1rem;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

#add-tile-tile {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius);
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(340px, 90vw);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

dialog h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

dialog label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

dialog input[type="text"],
dialog input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 8px 0 0;
}

body.edit-mode #edit-toggle-btn {
  background: var(--accent-active);
}
