:root {
  color-scheme: dark;
  --bg: #090e19;
  --surface: #111a29;
  --surface-raised: #162235;
  --line: rgba(157, 180, 211, .15);
  --accent: #63e6be;
  --accent-strong: #2dd4a2;
  --pink: #fb7185;
  --yellow: #f6c969;
  --text: #edf4fb;
  --muted: #8fa1b6;
  --mono: 'DM Mono', monospace;
  --body: 'Outfit', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; min-height: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); font-family: var(--body); overscroll-behavior: none; }
body { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; align-items: center; position: relative; }
button { font: inherit; }
.ambient-glow { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 42%, rgba(45,212,162,.10), transparent 48%), linear-gradient(135deg, rgba(99,230,190,.025), transparent 55%); }
.game-wrapper { position: relative; z-index: 1; width: min(100%, 1000px); height: 100%; max-height: 100dvh; padding: 20px 24px 14px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; }

.game-header { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.logo-box { text-align: left; }
.eyebrow { display: block; margin-bottom: 4px; color: var(--accent); font: 500 .62rem var(--mono); letter-spacing: .17em; }
.logo-box h1 { color: var(--text); font-size: clamp(1.1rem, 2.2vw, 1.5rem); font-weight: 800; letter-spacing: .035em; line-height: 1.1; }
.logo-box h1 span { color: var(--accent); }
.logo-box .subtitle { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.header-actions { display: flex; gap: 8px; }
.top-btn { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); font-size: 1rem; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; transition: background .15s, border-color .15s, transform .15s; }
.top-btn:hover { background: var(--surface-raised); border-color: rgba(99,230,190,.45); }
.top-btn:active { transform: scale(.96); }

.mobile-stats-bar { display: none; width: 100%; max-width: 440px; gap: 8px; margin-bottom: 8px; align-items: stretch; }
.m-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 5px 7px; }
.m-hold-card, .m-next-card { width: 68px; flex-shrink: 0; }
.m-tag { font: 500 .58rem var(--mono); color: var(--accent); letter-spacing: .08em; margin-bottom: 2px; }
.m-score-card { flex-grow: 1; }
.m-stat-row { display: flex; width: 100%; justify-content: space-around; align-items: center; }
.m-stat-item { display: flex; flex-direction: column; align-items: center; }
.m-lbl { font: 500 .48rem var(--mono); color: var(--muted); letter-spacing: .05em; }
.m-val { font: 500 .78rem var(--mono); color: var(--text); }
.m-val.highlight { color: var(--yellow); }

.main-layout { display: flex; justify-content: center; align-items: center; gap: clamp(16px, 3vw, 28px); width: 100%; flex-grow: 1; min-height: 0; }
.desktop-panel { display: flex; flex-direction: column; gap: 14px; width: 184px; }
.panel-box { background: rgba(17,26,41,.88); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 12px 32px rgba(0,0,0,.18); text-align: center; }
.panel-box h2, .panel-box h3 { font: 500 .7rem var(--mono); color: var(--muted); letter-spacing: .12em; margin-bottom: 12px; }
.panel-box .canvas-box { display: flex; justify-content: center; align-items: center; background: rgba(5,10,18,.75); border-radius: 10px; padding: 8px; border: 1px solid var(--line); margin-bottom: 6px; }
.hint-key { font: .65rem var(--mono); color: var(--muted); }
.stat-item { display: flex; flex-direction: column; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 9px 0; margin: 0; }
.stat-item:first-child { padding-top: 0; }
.stat-item:last-child { border-bottom: 0; padding-bottom: 0; }
.stat-label { font: 500 .58rem var(--mono); color: var(--muted); letter-spacing: .08em; }
.stat-value { font: 500 1.15rem var(--mono); color: var(--text); }
.stat-value.highlight { color: var(--yellow); }
.controls-guide ul { list-style: none; display: flex; flex-direction: column; gap: 8px; text-align: left; font-size: .72rem; color: var(--muted); }
.controls-guide li { display: flex; justify-content: space-between; gap: 8px; }
.controls-guide li span { font: 500 .65rem var(--mono); color: var(--accent); white-space: nowrap; }

.board-container { display: flex; justify-content: center; align-items: center; height: 100%; }
.canvas-frame { position: relative; background: #080e18; border: 1px solid rgba(99,230,190,.52); border-radius: 12px; box-shadow: 0 0 0 5px rgba(99,230,190,.045), 0 22px 60px rgba(0,0,0,.42); overflow: hidden; width: 310px; height: 620px; max-height: 72vh; aspect-ratio: 1 / 2; display: flex; justify-content: center; align-items: center; }
#tetrisCanvas { display: block; width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 2; }
.board-watermark { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font: 500 clamp(1rem, 2.8vw, 1.4rem)/1.5 var(--mono); color: rgba(237,244,251,.035); text-align: center; letter-spacing: .12em; z-index: 1; pointer-events: none; }
.float-text-layer { position: absolute; inset: 0; z-index: 15; pointer-events: none; overflow: hidden; }
.float-msg { position: absolute; left: 50%; transform: translate(-50%,0); font: 500 clamp(.8rem, 2.5vw, 1.05rem) var(--mono); text-align: center; white-space: nowrap; animation: floatUp 1.2s cubic-bezier(.18,.89,.32,1.28) forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%,20px) scale(.75); } 30% { opacity: 1; transform: translate(-50%,-10px) scale(1.08); } 70% { opacity: 1; transform: translate(-50%,-25px) scale(1); } 100% { opacity: 0; transform: translate(-50%,-50px) scale(.9); } }

.overlay-screen { position: absolute; inset: 0; background: rgba(7,12,21,.78); backdrop-filter: blur(7px); z-index: 20; display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity .25s ease; padding: 14px; }
.overlay-screen.active { opacity: 1; pointer-events: auto; }
.overlay-card { text-align: center; padding: 24px 20px; width: 92%; background: rgba(17,26,41,.97); border: 1px solid rgba(99,230,190,.38); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.overlay-card h2 { font: 700 1.15rem var(--body); color: var(--text); margin-bottom: 8px; letter-spacing: .04em; }
.overlay-card h2.title-pulse { color: var(--accent); font-size: 1.75rem; }
.overlay-card h2.text-danger { color: var(--pink); }
.overlay-card .badge { display: inline-block; background: rgba(99,230,190,.08); color: var(--accent); border: 1px solid rgba(99,230,190,.25); border-radius: 20px; font: 500 .58rem var(--mono); letter-spacing: .08em; padding: 5px 10px; margin-bottom: 14px; }
.overlay-card p { font-size: .86rem; color: var(--muted); line-height: 1.5; margin-bottom: 18px; }
.final-score-box { background: rgba(5,10,18,.75); border: 1px solid var(--line); border-radius: 10px; padding: 12px 10px; margin-bottom: 16px; font: 500 .7rem var(--mono); display: flex; justify-content: space-around; }
.glow-btn { background: var(--accent); border: 0; border-radius: 9px; color: #07130f; font-size: .9rem; font-weight: 700; letter-spacing: .02em; padding: 12px 16px; cursor: pointer; width: 100%; touch-action: manipulation; transition: transform .1s, background .15s; }
.glow-btn:hover { background: #83f1cf; }
.glow-btn:active { transform: scale(.98); }

.quote-strip { width: 100%; max-width: 440px; background: rgba(17,26,41,.82); border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; margin: 10px 0; display: flex; align-items: center; justify-content: center; gap: 9px; }
.quote-icon { font-size: .8rem; flex-shrink: 0; filter: grayscale(1); opacity: .7; }
.quote-strip p { font-size: .78rem; color: #b7c4d4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-controls { display: none; width: 100%; max-width: 440px; justify-content: space-between; align-items: center; gap: 12px; padding: 2px 4px 6px; }
.d-pad-group, .action-btn-group { display: flex; gap: 7px; }
.m-ctrl-btn { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; color: var(--text); font-size: 1.15rem; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; cursor: pointer; touch-action: manipulation; transition: transform .08s, background .08s; }
.m-ctrl-btn:active { background: var(--surface-raised); transform: scale(.94); }
.m-ctrl-btn.m-rotate-btn { background: rgba(99,230,190,.12); border-color: rgba(99,230,190,.4); }
.m-ctrl-btn.m-drop-btn { background: rgba(251,113,133,.12); border-color: rgba(251,113,133,.32); color: #ff9aaa; font: 500 .58rem var(--mono); width: 62px; }
.m-ctrl-btn.m-hold-btn { background: rgba(246,201,105,.1); border-color: rgba(246,201,105,.3); color: var(--yellow); font: 500 .52rem var(--mono); width: 56px; }
.game-footer { font-size: .68rem; color: var(--muted); text-align: center; margin-top: 4px; }
.game-footer strong { color: #b8c6d7; font-weight: 600; }

@media (max-width: 768px) {
  body { justify-content: flex-start; padding: 0; }
  .game-wrapper { padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom)); height: 100dvh; max-height: 100dvh; justify-content: space-between; }
  .game-header { margin-bottom: 4px; }
  .eyebrow { font-size: .53rem; }
  .logo-box h1 { font-size: clamp(.95rem, 4vw, 1.2rem); }
  .logo-box .subtitle { font-size: .7rem; }
  .top-btn { width: 36px; height: 36px; }
  .desktop-panel { display: none !important; }
  .mobile-stats-bar, .mobile-controls { display: flex; }
  .canvas-frame { width: auto; height: min(54dvh, 480px); aspect-ratio: 1 / 2; }
  .quote-strip { margin: 6px 0; padding: 8px 12px; }
  .game-footer { display: none; }
}
@media (max-height: 680px) {
  .logo-box .subtitle { display: none; }
  .canvas-frame { height: min(50dvh, 400px); }
  .m-ctrl-btn { width: 44px; height: 44px; font-size: 1.02rem; }
  .m-ctrl-btn.m-drop-btn { width: 54px; }
  .m-ctrl-btn.m-hold-btn { width: 48px; }
  .quote-strip { margin: 3px 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; } }
