:root {
  color-scheme: dark;
  --bg: #090b16;
  --surface: rgba(18, 21, 39, 0.78);
  --surface-strong: #121528;
  --line: rgba(170, 184, 255, 0.13);
  --muted: #7f89a8;
  --text: #f4f6ff;
  --cyan: #35d9ff;
  --violet: #9b70ff;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    linear-gradient(rgba(113, 132, 210, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(113, 132, 210, 0.028) 1px, transparent 1px),
    radial-gradient(circle at 50% -10%, #1a2045 0, var(--bg) 42%);
  background-size: 38px 38px, 38px 38px, auto;
}

button, dialog { font: inherit; }
button { color: inherit; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.ambient {
  position: fixed;
  width: 440px;
  height: 440px;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.09;
  pointer-events: none;
}

.ambient-one { top: 10%; left: -260px; background: #4e6cff; }
.ambient-two { right: -280px; bottom: 0; background: #d654ff; }

.app-shell {
  position: relative;
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 13px;
  letter-spacing: 0.12em;
}

.brand strong { font-size: 1.02rem; font-weight: 850; }
.brand em { color: var(--cyan); font-size: 0.72rem; font-style: normal; font-weight: 800; margin-left: 5px; vertical-align: super; }

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 8px);
  grid-template-rows: repeat(2, 8px);
  gap: 2px;
  transform: rotate(-3deg);
}

.brand-mark i { background: var(--cyan); box-shadow: 0 0 10px rgba(53, 217, 255, 0.55); }
.brand-mark i:nth-child(1) { grid-column: 2; }
.brand-mark i:nth-child(2) { grid-column: 1; grid-row: 2; }
.brand-mark i:nth-child(3) { grid-column: 2; grid-row: 2; }
.brand-mark i:nth-child(4) { grid-column: 3; grid-row: 2; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.text-button, .icon-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.text-button { border-radius: 10px; padding: 9px 13px; font-size: 0.76rem; color: #b3bad0; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; font-weight: 800; }
.text-button:hover, .icon-button:hover { border-color: rgba(53, 217, 255, 0.45); background: rgba(53, 217, 255, 0.08); }
.text-button:active, .icon-button:active { transform: scale(0.95); }

.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(280px, 340px) minmax(160px, 200px);
  gap: clamp(24px, 5vw, 66px);
  justify-content: center;
  align-items: center;
  padding: 32px 0 26px;
}

.side-column { display: flex; flex-direction: column; gap: 14px; }
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(23, 27, 50, 0.86), rgba(13, 16, 31, 0.82));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.panel-heading {
  height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  color: #c2c8dc;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.65rem;
  font-weight: 800;
}

.panel-heading small { color: var(--muted); font-size: 0.52rem; letter-spacing: 0.03em; text-transform: none; font-weight: 600; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 23px;
  height: 22px;
  padding: 0 5px;
  border: 1px solid rgba(190, 200, 255, 0.2);
  border-bottom-color: rgba(190, 200, 255, 0.36);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.045);
  color: #aeb6d2;
  font: 600 0.62rem ui-monospace, SFMono-Regular, Menlo, monospace;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

.preview-canvas { display: block; width: 100%; height: 116px; }
.panel-note { margin: 0; padding: 0 12px 13px; color: #66708e; font-size: 0.64rem; text-align: center; }
.key-panel { padding-bottom: 7px; }
.key-list { margin: 5px 0 0; padding: 0 12px; }
.key-list div { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid rgba(170, 184, 255, 0.07); }
.key-list div:last-child { border-bottom: 0; }
.key-list dt { display: flex; gap: 4px; }
.key-list dd { margin: 0; color: #78829f; font-size: 0.65rem; }

.play-column { min-width: 0; }
.game-status {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 5px;
  color: #8c96b5;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.57rem;
  font-weight: 800;
}
.live-dot { width: 5px; height: 5px; border-radius: 50%; margin-right: 7px; background: #57e88a; box-shadow: 0 0 9px #57e88a; }
.status-level { margin-left: auto; }
.status-level strong { color: var(--text); }

.board-frame {
  position: relative;
  padding: 7px;
  border: 1px solid rgba(126, 145, 223, 0.24);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(41, 48, 83, 0.68), rgba(15, 18, 34, 0.92));
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.48), 0 0 70px rgba(65, 91, 180, 0.09);
}

#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 2;
  border-radius: 7px;
  background: #080a14;
}

.board-corner { position: absolute; z-index: 2; width: 8px; height: 8px; border-color: rgba(53, 217, 255, 0.7); pointer-events: none; }
.top-left { top: 3px; left: 3px; border-top: 1px solid; border-left: 1px solid; }
.top-right { top: 3px; right: 3px; border-top: 1px solid; border-right: 1px solid; }
.bottom-left { bottom: 3px; left: 3px; border-bottom: 1px solid; border-left: 1px solid; }
.bottom-right { bottom: 3px; right: 3px; border-bottom: 1px solid; border-right: 1px solid; }

.event-toast {
  position: absolute;
  z-index: 3;
  top: 43%;
  left: 50%;
  padding: 8px 14px;
  transform: translate(-50%, 8px) scale(0.92);
  border: 1px solid rgba(53, 217, 255, 0.45);
  border-radius: 999px;
  background: rgba(5, 8, 20, 0.88);
  box-shadow: 0 0 28px rgba(53, 217, 255, 0.2);
  color: white;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.event-toast.show { animation: toast-pop 1.2s ease both; }
@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.9); }
  16%, 70% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.96); }
}

.stats-panel { padding: 17px 16px 14px; }
.stat-primary span, .stat-grid span { display: block; color: #747f9e; font-size: 0.58rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.stat-primary strong { display: block; margin-top: 5px; font: 700 clamp(1.55rem, 2.4vw, 2rem) ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -0.06em; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); }
.stat-grid div + div { padding-left: 13px; border-left: 1px solid var(--line); }
.stat-grid strong { display: block; margin-top: 5px; font: 700 0.82rem ui-monospace, SFMono-Regular, Menlo, monospace; color: #cdd2e3; }

.next-canvas { display: block; width: 100%; height: 276px; }
.streak-card { padding: 13px 15px; border: 1px solid rgba(155, 112, 255, 0.2); border-radius: 13px; background: rgba(110, 75, 200, 0.07); }
.streak-card span { display: block; color: #777f9b; font-size: 0.57rem; text-transform: uppercase; letter-spacing: 0.09em; }
.streak-card strong { display: block; margin-top: 4px; color: #cbbcff; font-size: 0.72rem; }

.touch-controls { display: none; }

footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: #59627e;
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
footer i { width: 3px; height: 3px; border-radius: 50%; background: #454d66; }

dialog {
  width: min(620px, calc(100% - 28px));
  padding: 0;
  border: 1px solid rgba(156, 173, 242, 0.2);
  border-radius: 22px;
  color: var(--text);
  background: #111528;
  box-shadow: 0 36px 100px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(4, 5, 12, 0.78); backdrop-filter: blur(8px); }
.dialog-card { padding: 28px; }
.dialog-top { display: flex; justify-content: space-between; align-items: start; }
.eyebrow { color: var(--cyan); font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 800; }
.dialog-card h2 { margin: 6px 0 0; font-size: 1.7rem; }
.dialog-card > p { max-width: 480px; color: #929ab3; font-size: 0.82rem; line-height: 1.6; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 20px 0; }
.guide-grid > div { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 7px; padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,0.018); }
.key-pair { display: flex; gap: 4px; }
.guide-grid strong { font-size: 0.71rem; }
.guide-grid .guide-copy { grid-column: 1 / -1; margin-top: 6px; color: #707994; font-size: 0.63rem; }
.primary-button { width: 100%; height: 43px; border: 0; border-radius: 11px; background: linear-gradient(90deg, #487aff, #8a68ff); color: white; font-weight: 800; font-size: 0.74rem; cursor: pointer; }

@media (max-width: 820px) {
  .game-layout { grid-template-columns: minmax(120px, 170px) minmax(260px, 330px); align-items: start; }
  .play-column { grid-column: 2; grid-row: 1 / span 2; }
  .left-column { grid-column: 1; grid-row: 1; }
  .right-column { grid-column: 1; grid-row: 2; }
  .key-panel, .streak-card { display: none; }
  .next-canvas { height: 220px; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 22px, 410px); }
  .topbar { height: 66px; }
  .text-button { display: none; }
  .game-layout { display: flex; flex-wrap: wrap; gap: 12px; padding-top: 13px; align-items: stretch; }
  .play-column { order: 1; width: 100%; max-width: 315px; margin: 0 auto; }
  .left-column { order: 2; width: calc(42% - 6px); }
  .right-column { order: 3; width: calc(58% - 6px); }
  .piece-panel, .stats-panel, .next-panel { height: 100%; }
  .preview-canvas { height: 88px; }
  .panel-note { display: none; }
  .right-column { display: grid; grid-template-columns: 0.9fr 1.1fr; }
  .stats-panel { padding: 13px 11px; }
  .stat-grid { grid-template-columns: 1fr; gap: 9px; }
  .stat-grid div + div { padding: 9px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .stat-primary strong { font-size: 1.2rem; }
  .next-canvas { height: 136px; }
  .next-panel .panel-heading small { display: none; }
  .touch-controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 12px; touch-action: none; }
  .touch-controls button { min-height: 43px; border: 1px solid var(--line); border-radius: 10px; background: rgba(28, 33, 59, 0.9); font-weight: 800; cursor: pointer; }
  .touch-controls button:active { background: rgba(53, 217, 255, 0.14); transform: translateY(1px); }
  .touch-controls .drop-button { color: var(--cyan); border-color: rgba(53, 217, 255, 0.3); }
  .touch-controls .wide-touch { grid-column: span 2; min-height: 35px; color: #8e98b8; font-size: 0.63rem; }
  .touch-controls .wide-touch:last-child { grid-column: span 3; }
  footer { margin-top: 16px; min-height: 48px; gap: 7px; font-size: 0.46rem; }
  .guide-grid { grid-template-columns: 1fr; }
  .dialog-card { padding: 22px; }
}

@media (max-height: 760px) and (min-width: 561px) {
  .topbar { height: 66px; }
  .game-layout { padding-top: 12px; padding-bottom: 12px; }
  .play-column { max-width: 296px; justify-self: center; }
  footer { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
