:root {
  --bg: #0b1020;
  --panel: #131a30;
  --line: #243055;
  --text: #e6ebff;
  --muted: #8a94b8;
  --accent: #ff5d8f;
  --side: 112px;
  --gap: 16px;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  background: radial-gradient(ellipse at top, #1a2350, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.logo { font-size: 28px; letter-spacing: .2em; font-weight: 800; }
.logo span { color: var(--accent); }

.game {
  display: grid;
  grid-template-columns: var(--side) auto var(--side);
  gap: var(--gap);
  align-items: start;
}

.panel { display: flex; flex-direction: column; gap: 12px; }

.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.box h2 { font-size: 11px; letter-spacing: .15em; color: var(--muted); margin-bottom: 6px; }
.box canvas { display: block; width: 100%; height: auto; }

.stats { display: grid; gap: 2px; }
.stats dt { font-size: 11px; letter-spacing: .15em; color: var(--muted); }
.stats dd { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 6px; }

.keys { list-style: none; display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
}

.board-wrap { position: relative; }

#board {
  display: block;
  /* 1:2 비율 유지, 뷰포트 높이·폭 모두에 맞춰 축소 */
  height: min(600px, 78svh, (100vw - 32px - 2 * var(--side) - 2 * var(--gap)) * 2);
  aspect-ratio: 1 / 2;
  background: #070b18;
  border: 2px solid var(--line);
  border-radius: 8px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgb(7 11 24 / .82);
  border-radius: 8px;
  text-align: center;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.overlay-msg { font-size: 22px; font-weight: 800; white-space: pre-line; }
.hint { color: var(--muted); font-size: 12px; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
#start-btn { background: var(--accent); border: 0; padding: 10px 26px; font-weight: 700; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 터치 컨트롤: 십자 배열, 터치 기기에서만 노출 */
.touch {
  --btn: 68px;
  display: none;
  grid-template: repeat(3, var(--btn)) / repeat(3, var(--btn));
  grid-template-areas:
    ".    rot   ."
    "left .     right"
    ".    down  .";
  gap: 6px;
  touch-action: none;
}
.touch button { font-size: 26px; border-radius: 16px; }
.touch button:active { background: var(--line); transform: scale(.94); }
.t-rot   { grid-area: rot; }
.t-left  { grid-area: left; }
.t-right { grid-area: right; }
.t-down  { grid-area: down; }

@media (pointer: coarse) {
  .touch { display: grid; }
  .keys { display: none; }
  /* 십자 패드(3×68px + 여백) 높이만큼 보드를 줄여 한 화면에 들어오게 */
  #board { height: min(600px, 100svh - 330px, (100vw - 32px - 2 * var(--side) - 2 * var(--gap)) * 2); }
}

@media (max-width: 560px) {
  :root { --side: 72px; --gap: 8px; }
  .logo { font-size: 20px; }
  .box { padding: 6px; }
  .stats dd { font-size: 14px; }
}

.link { color: var(--accent); }

/* 키 작은 폰(iPhone SE 등): 사이드 패널이 보드보다 길어지지 않게 압축 */
@media (pointer: coarse) and (max-height: 700px) {
  .app { gap: 8px; padding-block: 10px; }
  .logo { font-size: 18px; }
  .panel { gap: 8px; }
  .stats dt { font-size: 9px; }
  .stats dd { font-size: 13px; margin-bottom: 2px; }
  .touch { --btn: 60px; }
}
