:root {
  --bg: #10131a;
  --surface: rgba(25, 29, 39, 0.88);
  --surface-solid: #191d27;
  --surface-raised: #232837;
  --text: #f7f7f2;
  --muted: #9ca5b7;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.15);
  --accent: #ffe66d;
  --accent-2: #7cf7c9;
  --tone-1: #ffdc5d;
  --tone-2: #66e0c2;
  --tone-3: #79a7ff;
  --tone-4: #ff7aa2;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html {
  height: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -10%, rgba(124, 247, 201, 0.1), transparent 33%),
    radial-gradient(circle at 90% 5%, rgba(255, 230, 109, 0.09), transparent 28%),
    var(--bg);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }
.shell { width: min(1440px, calc(100% - 28px)); margin-inline: auto; }

.glow {
  position: fixed;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.14;
  pointer-events: none;
  z-index: -1;
}
.glow-one { background: var(--accent-2); top: 10vh; left: -180px; }
.glow-two { background: var(--tone-4); top: 42vh; right: -220px; }

.topbar { flex-shrink: 0; padding: 10px 0 4px; }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.03em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #16181d;
  transform: rotate(-4deg);
  box-shadow: 0 8px 18px rgba(255, 230, 109, 0.16);
}
.nav-actions { display: flex; gap: 6px; }
.ghost-button,
.share-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  border-radius: 999px;
  padding: 7px 11px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.ghost-button:hover,
.share-button:hover:not(:disabled) { transform: translateY(-1px); background: rgba(255, 255, 255, 0.07); }
.ghost-button[aria-pressed="true"] { border-color: rgba(124, 247, 201, 0.5); background: rgba(124, 247, 201, 0.1); }
.share-button:disabled { opacity: 0.4; cursor: default; }

.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 4px;
  padding-bottom: 12px;
}
.control-deck {
  flex-shrink: 0;
  z-index: 50;
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(16, 19, 26, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.search-wrap {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid transparent;
  transition: border-color 160ms ease, background 160ms ease;
}
.search-wrap:focus-within { border-color: rgba(255, 230, 109, 0.55); background: rgba(255, 255, 255, 0.075); }
.search-icon { color: var(--accent); font-size: 20px; line-height: 1; transform: rotate(-12deg); }
.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
}
.search-wrap input::-webkit-search-decoration,
.search-wrap input::-webkit-search-cancel-button,
.search-wrap input::-webkit-search-results-button,
.search-wrap input::-webkit-search-results-decoration { display: none; }
.search-wrap input::placeholder { color: #737d91; }
.clear-search {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  font-size: 16px;
}
.tone-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.tone-mode-btn {
  min-width: 36px;
  height: 28px;
  padding: 0 9px;
  border: 2px solid transparent;
  border-radius: 999px;
  color: #11141a;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  opacity: 0.55;
  transition: opacity 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}
.tone-mode-btn:hover { opacity: 0.85; transform: translateY(-1px); }
.tone-mode-btn.is-active {
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 6px 14px rgba(0, 0, 0, 0.18);
}
.tone-1 { background: var(--tone-1); }
.tone-2 { background: var(--tone-2); }
.tone-3 { background: var(--tone-3); }
.tone-4 { background: var(--tone-4); }
.tone-all {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line-strong);
}
.tone-all.is-active {
  color: #11141a;
  background: var(--accent);
  border-color: transparent;
}
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-color: rgba(255, 255, 255, 0.17);
  border-radius: 6px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
  font-size: 10px;
  font-family: inherit;
}
.status-line { padding: 0 2px; color: var(--muted); font-size: 11px; }

.play-toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, calc(18px + env(safe-area-inset-bottom, 0px)));
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(22, 26, 36, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.48);
  transform: translate(-50%, calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms ease, opacity 220ms ease;
}
.play-toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}
.play-toast-copy {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1px 8px;
  min-width: 0;
}
.now-label {
  width: 100%;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
#nowSyllable {
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 18px;
  letter-spacing: -0.03em;
}
#nowHint {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.map-heading {
  flex-shrink: 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.map-kicker {
  display: block;
  margin-bottom: 1px;
  color: var(--accent-2);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.map-heading h2 {
  margin: 0;
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 17px;
  letter-spacing: -.035em;
}
.map-heading p {
  max-width: 320px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: right;
}

.matrix-scroller {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #4d566a #181c25;
  scrollbar-width: thin;
  cursor: grab;
  user-select: none;
  touch-action: pan-x pan-y;
}
.matrix-scroller.is-dragging { cursor: grabbing; }
.matrix-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: rgba(9, 12, 17, .18);
}
.matrix-table th,
.matrix-table td {
  width: 84px;
  min-width: 84px;
  height: 42px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.matrix-table thead th {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 30;
  height: 36px;
  background: #1d2230;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}
.corner-cell {
  position: sticky !important;
  left: 0;
  z-index: 40 !important;
  width: 64px !important;
  min-width: 64px !important;
  color: var(--muted);
  background: #202634 !important;
  text-align: left;
}
.corner-cell span { display: block; padding-left: 7px; font-size: 9px; line-height: 1.25; }
.corner-cell span:last-child { color: var(--accent); }
.final-header {
  color: #dce2ee;
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 900;
  transition: background 120ms ease, color 120ms ease;
}
.initial-header {
  position: sticky;
  left: 0;
  z-index: 20;
  width: 64px !important;
  min-width: 64px !important;
  color: #11141a;
  background: var(--accent-2);
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
  box-shadow: 5px 0 12px rgba(0, 0, 0, .14);
  transition: filter 120ms ease, box-shadow 120ms ease;
}
.matrix-empty {
  background:
    linear-gradient(135deg, transparent 49%, rgba(255,255,255,.025) 49%, rgba(255,255,255,.025) 51%, transparent 51%),
    rgba(255,255,255,.012);
  transition: background 120ms ease;
}
.syllable-cell {
  position: relative;
  padding: 2px;
  background: rgba(255,255,255,.025);
  text-align: center;
  cursor: pointer;
  transition: opacity 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
.syllable-cell:hover { background: rgba(255,255,255,.065); }
.syllable-cell:hover .cell-syllable { color: var(--accent); }
.syllable-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.syllable-cell.is-filtered { opacity: .12; }
.syllable-cell.is-match {
  background: rgba(255, 230, 109, .08);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 109, .3);
}
.syllable-cell.is-target { box-shadow: inset 0 0 0 2px var(--accent), 0 0 18px rgba(255, 230, 109, .16); }
.syllable-cell.is-playing {
  background: rgba(255, 230, 109, .14);
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 14px rgba(255, 230, 109, .18);
}
.syllable-cell.is-missing { opacity: .35; }
.syllable-cell.is-crosshair,
.matrix-empty.is-crosshair {
  background: rgba(124, 247, 201, 0.08);
}
.final-header.is-crosshair-axis {
  color: #11141a;
  background: var(--accent);
}
.initial-header.is-crosshair-axis {
  filter: brightness(1.08);
  box-shadow: 5px 0 12px rgba(0, 0, 0, .14), inset 0 0 0 2px rgba(17, 20, 26, 0.35);
}
.cell-syllable {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  pointer-events: none;
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -.02em;
}

.site-footer {
  flex-shrink: 0;
  padding: 2px 12px 8px;
  text-align: center;
}
.site-footer p {
  margin: 0;
  color: rgba(156, 165, 183, 0.72);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.empty-state { flex-shrink: 0; margin: 12px auto 0; max-width: 540px; text-align: center; color: var(--muted); }
.empty-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border-radius: 14px;
  color: #11141a;
  background: var(--tone-4);
  font-family: "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 900;
  transform: rotate(4deg);
}
.empty-state h2 { margin: 0 0 4px; color: var(--text); font-size: 20px; }
.text-button { padding: 0; border: 0; color: var(--accent-2); background: none; cursor: pointer; text-decoration: underline; }

@media (max-width: 760px) {
  .shell { width: min(100% - 10px, 1440px); }
  .topbar { padding: 6px 0 0; }
  .brand { font-size: 15px; gap: 7px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; font-size: 12px; }
  .ghost-button,
  .share-button { padding: 5px 9px; font-size: 12px; }
  .nav-actions .ghost-button:first-child { display: none; }
  .main-content { padding-top: 2px; padding-bottom: 4px; }
  .site-footer { padding: 2px 10px 8px; }
  .site-footer p { font-size: 10px; }
  .control-deck {
    gap: 5px;
    padding: 7px;
    border-radius: 14px;
  }
  .search-wrap { min-height: 36px; gap: 7px; padding: 0 9px; border-radius: 10px; }
  .search-icon { font-size: 16px; }
  .search-wrap input { font-size: 14px; }
  .clear-search { width: 22px; height: 22px; font-size: 15px; }
  .tone-mode { gap: 4px; }
  .tone-mode-btn { min-width: 30px; height: 24px; padding: 0 7px; font-size: 11px; }
  .status-line { font-size: 10px; }
  .map-card { margin-top: 6px; border-radius: 14px; }
  .map-heading { display: none; }
  .matrix-table th,
  .matrix-table td { width: 64px; min-width: 64px; height: 34px; }
  .matrix-table thead th { height: 30px; }
  .corner-cell,
  .initial-header { width: 44px !important; min-width: 44px !important; }
  .corner-cell span { padding-left: 4px; font-size: 7px; }
  .final-header { font-size: 11px; }
  .initial-header { font-size: 12px; box-shadow: 3px 0 8px rgba(0, 0, 0, .12); }
  .cell-syllable { font-size: 12px; }
  .play-toast {
    bottom: max(24px, calc(14px + env(safe-area-inset-bottom, 0px)));
    max-width: calc(100% - 28px);
    padding: 8px 10px;
    gap: 10px;
    border-radius: 12px;
  }
  .play-toast-copy { flex: 0 1 auto; }
  .share-button { flex-shrink: 0; }
  .now-label { display: none; }
  #nowSyllable { font-size: 15px; }
  #nowHint { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
