@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Noto+Sans+SC:wght@400;500;700;900&display=swap');

:root {
  --paper: #f2ead8;
  --ink: #20211e;
  --muted: #777365;
  --red: #e2472f;
  --red-dark: #ba3322;
  --line: rgba(32, 33, 30, .18);
  --screen: #151916;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Sans SC", sans-serif;
  background:
    linear-gradient(rgba(57, 51, 38, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 51, 38, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid #f1b632; outline-offset: 3px; }

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.topbar {
  height: 82px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { color: inherit; display: flex; gap: 13px; align-items: center; text-decoration: none; font-weight: 900; letter-spacing: -.04em; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 7px); grid-template-rows: repeat(2, 7px); gap: 2px; transform: rotate(-5deg); }
.brand-mark i { background: var(--red); display: block; }
.brand-mark i:nth-child(2) { grid-column: 2; grid-row: 2; }
.brand-mark i:nth-child(3) { grid-column: 3; grid-row: 2; }
.brand-mark i:nth-child(4) { grid-column: 2; grid-row: 1; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.status-dot { font: 500 11px "DM Mono", monospace; text-transform: uppercase; letter-spacing: .08em; }
.status-dot i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #3d8e5f; margin-right: 7px; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; padding: 46px 0 38px; }
.eyebrow, .panel-label { font: 500 10px "DM Mono", monospace; letter-spacing: .16em; text-transform: uppercase; }
.eyebrow { color: var(--red); margin: 0 0 12px; }
h1 { font-size: clamp(38px, 5vw, 68px); line-height: .98; letter-spacing: -.08em; margin: 0; font-weight: 900; }
h1 em { color: var(--red); font-style: normal; }
.intro { margin: 0 0 4px; font-size: 13px; line-height: 1.8; color: var(--muted); text-align: right; }

.game-layout { display: grid; grid-template-columns: 200px 362px 220px; gap: 34px; justify-content: center; align-items: center; }
.side-panel { min-height: 500px; }
.left-panel { padding-top: 10px; }
.panel-label { border-bottom: 1px solid var(--line); padding-bottom: 9px; margin-bottom: 12px; }
#holdCanvas, #nextCanvas { width: 100%; height: auto; background: rgba(255,255,255,.18); border: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 10px; margin: 8px 0 38px; }
kbd { min-width: 24px; height: 23px; padding: 3px 6px; display: inline-flex; justify-content: center; align-items: center; background: #f8f2e6; border: 1px solid rgba(32,33,30,.35); border-radius: 3px; box-shadow: 0 2px 0 rgba(32,33,30,.2); font: 500 10px "DM Mono", monospace; }
.key-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 11px; }
.key-row span { display: flex; gap: 4px; }
.key-row b { font-weight: 500; color: var(--muted); }

.machine { background: #d84830; border: 2px solid var(--ink); border-radius: 10px; padding: 13px 18px 22px; box-shadow: 9px 11px 0 rgba(32,33,30,.16), inset 0 1px rgba(255,255,255,.3); }
.machine-head { color: #f7e9d4; display: flex; justify-content: space-between; align-items: center; padding: 1px 0 10px; font: 500 9px "DM Mono", monospace; letter-spacing: .12em; }
.pause-btn { border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; letter-spacing: .05em; }
.board-wrap { position: relative; background: var(--screen); border: 3px solid #86291d; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }
#gameCanvas { width: 100%; height: auto; display: block; image-rendering: pixelated; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 25px; background: rgba(17,20,18,.74); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.overlay.visible { opacity: 1; pointer-events: auto; }
.overlay-card { width: 100%; padding: 25px 20px 20px; text-align: center; background: var(--paper); border: 1px solid var(--ink); box-shadow: 6px 6px 0 var(--red); }
.mini-blocks { color: var(--red); font-size: 28px; }
.overlay-card p { color: var(--muted); font-size: 11px; line-height: 1.7; margin: 8px 0; }
.overlay-card h2 { margin: 2px 0 9px; font-size: 26px; letter-spacing: -.07em; }
.primary-btn { width: 100%; margin-top: 10px; padding: 11px 14px; border: 1px solid var(--ink); background: var(--red); color: white; font-weight: 700; cursor: pointer; display: flex; justify-content: space-between; }
.primary-btn:hover { background: var(--red-dark); }

.right-panel { display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.score-card { border: 1px solid var(--line); padding: 14px; background: rgba(255,255,255,.13); }
.score-card span, .best-card span { display: block; font: 500 9px "DM Mono", monospace; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.score-card strong, .best-card strong { font: 500 24px "DM Mono", monospace; }
.score-card.featured { background: var(--ink); color: var(--paper); border-color: var(--ink); padding: 18px; }
.score-card.featured span { color: rgba(242,234,216,.58); }
.score-card.featured strong { display: block; font-size: 32px; letter-spacing: .06em; }
.score-card small { color: #d9a734; font-size: 9px; }
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.next-card { margin-top: 8px; }
.best-card { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 12px; display: flex; justify-content: space-between; align-items: flex-end; }
.best-card span { margin: 0; }
.best-card strong { font-size: 14px; }

.mobile-controls { display: none; }
footer { border-top: 1px solid var(--line); margin-top: 48px; min-height: 74px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font: 500 9px "DM Mono", monospace; letter-spacing: .08em; }

@media (max-width: 900px) {
  .app-shell { width: min(680px, calc(100% - 28px)); }
  .hero { padding: 32px 0 28px; }
  .intro { display: none; }
  .game-layout { grid-template-columns: minmax(120px, 180px) minmax(290px, 350px); gap: 20px; }
  .right-panel { grid-column: 1; grid-row: 1; }
  .left-panel { display: none; }
  .machine { grid-column: 2; grid-row: 1; }
}

@media (max-width: 580px) {
  .app-shell { width: min(100% - 20px, 390px); }
  .topbar { height: 62px; }
  .status-dot { display: none; }
  .hero { padding: 24px 0 22px; }
  h1 { font-size: 40px; }
  .game-layout { display: flex; flex-direction: column; gap: 14px; }
  .machine { width: min(100%, 344px); order: 1; padding: 10px 14px 17px; }
  .right-panel { order: 2; width: 100%; min-height: auto; display: grid; grid-template-columns: 1.3fr .7fr; }
  .score-card.featured { grid-row: span 2; }
  .stats-row { grid-template-columns: 1fr; gap: 12px; }
  .next-card, .best-card { display: none; }
  .mobile-controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 14px auto 0; width: 100%; }
  .mobile-controls button { border: 1px solid var(--ink); background: rgba(255,255,255,.25); min-height: 48px; font-size: 19px; box-shadow: 0 3px 0 rgba(32,33,30,.24); border-radius: 4px; touch-action: manipulation; }
  .mobile-controls .drop-btn { background: var(--ink); color: var(--paper); font-size: 11px; }
  footer { margin-top: 30px; justify-content: center; }
  footer span:not(:nth-child(2)) { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
