:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #000;
  --glass: rgba(9, 11, 17, .72);
  --line: rgba(255, 255, 255, .14);
  --muted: rgba(255, 255, 255, .62);
  --accent: #9cff00;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; background: #000; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; font: inherit; }

.tiles-app { position: fixed; inset: 0; isolation: isolate; background: #000; }
#tiles-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; touch-action: manipulation; }

.tiles-topbar {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.tiles-topbar > * { pointer-events: auto; }
.round-button, .source-button, .mode-title, .control-dock, .player-controls {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .28);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
}
.round-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  text-decoration: none;
  cursor: pointer;
}
.home-button span { font-size: 25px; line-height: 1; transform: translateY(-1px); }
.round-button:hover, .round-button:focus-visible, .source-button:hover, .source-button:focus-visible, .mode-title:hover, .mode-title:focus-visible { border-color: rgba(156, 255, 0, .56); outline: none; }

.mode-title {
  min-width: 0;
  width: fit-content;
  max-width: min(390px, 100%);
  min-height: 54px;
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 9px;
  align-items: center;
  padding: 8px 14px 9px;
  border-radius: 18px;
  text-align: left;
  cursor: pointer;
}
.mode-kicker, .dialog-kicker { color: var(--accent); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.mode-title strong { grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.mode-count { grid-column: 2; grid-row: 1 / 3; color: var(--muted); font-size: 12px; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.source-button {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 999px;
  cursor: pointer;
}
.source-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 13px var(--accent); }
.source-button[data-source="microphone"] .source-dot { background: #ff2b88; box-shadow: 0 0 13px #ff2b88; }
.source-button[data-source="player"] .source-dot { background: #00eaff; box-shadow: 0 0 13px #00eaff; }
.source-button span:last-child { font-size: 12px; font-weight: 750; white-space: nowrap; }
.fullscreen-icon { width: 18px; height: 18px; border: 2px solid currentColor; clip-path: polygon(0 0, 42% 0, 42% 14%, 14% 14%, 14% 42%, 0 42%, 0 0, 100% 0, 100% 42%, 86% 42%, 86% 14%, 58% 14%, 58% 0, 100% 0, 100% 100%, 58% 100%, 58% 86%, 86% 86%, 86% 58%, 100% 58%, 100% 100%, 0 100%, 0 58%, 14% 58%, 14% 86%, 42% 86%, 42% 100%, 0 100%); }

.control-dock {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 3px;
  max-width: calc(100% - 22px);
  padding: 6px;
  border-radius: 22px;
}
.control-button, .tempo-control button {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.control-button {
  width: 69px;
  min-height: 57px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 16px;
  color: rgba(255,255,255,.84);
}
.control-button img { width: 25px; height: 25px; opacity: .82; }
.control-button span:last-child, .tempo-control > span { color: var(--muted); font-size: 9px; font-weight: 750; white-space: nowrap; }
.control-button:hover, .control-button:focus-visible, .tempo-control button:hover, .tempo-control button:focus-visible { background: rgba(255,255,255,.09); outline: none; }
.control-button[aria-pressed="true"] { background: rgba(255,255,255,.11); color: #fff; }
.sensitivity-button b { font-size: 25px; line-height: 1; font-weight: 500; }
.variant-icon { width: 23px; height: 23px; display: block; position: relative; }
.variant-grid { border: 2px solid currentColor; background: linear-gradient(90deg, transparent 29%, currentColor 30% 35%, transparent 36% 64%, currentColor 65% 70%, transparent 71%), linear-gradient(transparent 29%, currentColor 30% 35%, transparent 36% 64%, currentColor 65% 70%, transparent 71%); }
.variant-glow { border: 2px solid currentColor; box-shadow: 0 0 5px currentColor, inset 0 0 5px currentColor; }
.variant-circle { border: 2px solid currentColor; border-radius: 50%; }
.variant-star::before { content: "\2605"; position: absolute; inset: -5px 0 0; font-size: 28px; line-height: 1; }

.tempo-control {
  min-width: 119px;
  display: grid;
  grid-template-columns: 35px 42px 35px;
  grid-template-rows: 36px 13px;
  align-items: center;
  justify-items: center;
  border-left: 1px solid rgba(255,255,255,.1);
  margin-left: 2px;
  padding-left: 2px;
}
.tempo-control button { width: 34px; height: 34px; border-radius: 11px; font-size: 25px; line-height: 1; }
.tempo-control output { font-size: 22px; font-variant-numeric: tabular-nums; }
.tempo-control > span { grid-column: 1 / -1; }

.player-controls {
  position: absolute;
  z-index: 4;
  right: max(15px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 82px);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 999px;
}
.player-controls[hidden] { display: none; }
.player-controls button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: #fff; cursor: pointer; }
.player-controls button:hover, .player-controls button:focus-visible { background: rgba(255,255,255,.1); outline: none; }
.player-controls .player-main { background: #fff; color: #000; }

.stage-hint { position: absolute; z-index: 3; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 89px); transform: translateX(-50%); margin: 0; padding: 7px 12px; border-radius: 999px; color: rgba(255,255,255,.72); background: rgba(0,0,0,.38); font-size: 11px; pointer-events: none; animation: hint-away .6s 5s forwards; }
@keyframes hint-away { to { opacity: 0; visibility: hidden; } }
.toast { position: absolute; z-index: 20; left: 50%; top: 84px; transform: translate(-50%, -8px); max-width: min(460px, calc(100% - 32px)); padding: 9px 14px; border-radius: 999px; color: #fff; background: rgba(17,17,22,.92); border: 1px solid var(--line); font-size: 13px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.app-dialog {
  width: min(520px, calc(100% - 24px));
  max-height: min(720px, calc(100% - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 26px;
  color: #fff;
  background: rgba(11,12,17,.94);
  box-shadow: 0 30px 100px rgba(0,0,0,.64);
  backdrop-filter: blur(28px) saturate(1.2);
}
.app-dialog::backdrop { background: rgba(0,0,0,.44); backdrop-filter: blur(5px); }
.app-dialog form { padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.dialog-heading h1 { margin: 3px 0 0; font-size: 25px; letter-spacing: -.03em; }
.dialog-close { width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); font-size: 25px; cursor: pointer; }
.dialog-copy { margin: 10px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.swatch-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.swatch {
  aspect-ratio: 1;
  min-width: 0;
  position: relative;
  border: 2px solid transparent;
  border-radius: 15px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 6px 20px color-mix(in srgb, var(--swatch), transparent 74%);
  cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: #fff; transform: scale(.92); }
.swatch[aria-pressed="true"]::after { content: "\2713"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--check, #000); font-size: 20px; font-weight: 900; text-shadow: 0 1px 2px rgba(255,255,255,.18); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; padding: 14px 2px 4px; cursor: pointer; }
.switch-row span { display: grid; gap: 3px; }
.switch-row strong { font-size: 14px; }
.switch-row small { color: var(--muted); font-size: 11px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i { width: 48px; height: 27px; flex: 0 0 auto; position: relative; border-radius: 999px; background: rgba(255,255,255,.18); transition: .2s; }
.switch-row i::after { content: ""; position: absolute; top: 4px; left: 4px; width: 19px; height: 19px; border-radius: 50%; background: #fff; transition: .2s; }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(21px); background: #0b0d05; }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.dialog-actions button { min-height: 45px; padding: 0 18px; border-radius: 14px; cursor: pointer; font-weight: 800; }
.reset-button { border: 1px solid var(--line); background: transparent; }
.done-button { min-width: 120px; border: 0; color: #0b0d05; background: var(--accent); }

.mode-list { display: grid; gap: 8px; margin-top: 18px; }
.mode-option { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 12px; width: 100%; padding: 11px; border: 1px solid transparent; border-radius: 16px; text-align: left; background: rgba(255,255,255,.045); cursor: pointer; }
.mode-option:hover, .mode-option:focus-visible { border-color: rgba(156,255,0,.5); outline: none; }
.mode-option[aria-current="true"] { background: rgba(156,255,0,.12); border-color: rgba(156,255,0,.3); }
.mode-number { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; color: #0b0d05; background: var(--accent); font-size: 12px; font-weight: 900; }
.mode-option strong { display: block; font-size: 14px; }
.mode-option small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.mode-option > span:last-child { color: var(--muted); }

@media (max-width: 760px) {
  .tiles-topbar { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .round-button { width: 44px; height: 44px; }
  .source-button { width: 44px; min-height: 44px; padding: 0; justify-content: center; }
  .source-button span:last-child { display: none; }
  .mode-title { min-height: 48px; padding: 6px 11px; border-radius: 15px; }
  .mode-title strong { font-size: 14px; }
  .control-dock { width: calc(100% - 18px); justify-content: center; gap: 0; bottom: max(8px, env(safe-area-inset-bottom)); padding: 4px; border-radius: 19px; }
  .control-button { flex: 1 1 0; width: auto; min-width: 0; min-height: 54px; padding: 0 2px; }
  .control-button span:last-child { max-width: 54px; overflow: hidden; text-overflow: ellipsis; }
  .tempo-control { min-width: 102px; grid-template-columns: 29px 39px 29px; }
  .tempo-control button { width: 29px; }
  .player-controls { right: 10px; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 70px); }
  .stage-hint { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 77px); }
  .swatch-grid { grid-template-columns: repeat(7, 1fr); gap: 7px; }
  .swatch { border-radius: 11px; }
}

@media (max-width: 460px) {
  .control-button { min-height: 50px; }
  .control-button img, .variant-icon { width: 21px; height: 21px; }
  .sensitivity-button b { font-size: 22px; }
  .control-button span:last-child, .tempo-control > span { font-size: 8px; }
  .tempo-control { min-width: 88px; grid-template-columns: 25px 36px 25px; }
  .tempo-control output { font-size: 19px; }
  .tempo-control button { width: 25px; font-size: 22px; }
  .app-dialog form { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-hint { animation: none; opacity: 0; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
