/* 스도쿠 — 화면 스타일 (모바일 우선) */

/* ---------- 색상 토큰 ---------- */
:root {
  color-scheme: light;
  --bg: #f3f4f9;
  --surface: #fff;
  --surface-2: #eceef6;
  --ink: #1b1e2e;
  --muted: #6a7088;
  --line: #d3d7e6;
  --line-strong: #3a3f5c;
  --accent: #4b57d1;
  --accent-ink: #fff;
  --accent-soft: #e3e6ff;
  --user: #3b4ad0;
  --wrong: #d93b42;
  --wrong-soft: #fde6e8;
  --cell: #fff;
  --peer: #eef0fb;
  --same: #cfd6ff;
  --sel: #b9c4ff;
  --clash: #fbdcde;
  --flash: #6f7cf0;
  --knob: #fff;
  --shadow: 0 1px 2px rgb(27 30 46 / 6%), 0 3px 12px rgb(27 30 46 / 6%);
  --shadow-lg: 0 12px 40px rgb(27 30 46 / 20%);
  --accent-glow: 0 6px 18px -6px rgb(75 87 209 / 60%);
  --backdrop: rgb(17 19 27 / 40%);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11131b;
    --surface: #1a1d29;
    --surface-2: #242838;
    --ink: #e9ebf5;
    --muted: #9ba1ba;
    --line: #2f3448;
    --line-strong: #7d84a8;
    --accent: #8a94ff;
    --accent-ink: #11131b;
    --accent-soft: #2b3060;
    --user: #9aa4ff;
    --wrong: #ff6e73;
    --wrong-soft: #3a1f27;
    --cell: #1a1d29;
    --peer: #222639;
    --same: #353d75;
    --sel: #424c94;
    --clash: #4a2229;
    --flash: #8a94ff;
    --knob: #e9ebf5;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 3px 12px rgb(0 0 0 / 22%);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 55%);
    --accent-glow: 0 6px 18px -8px rgb(138 148 255 / 45%);
    --backdrop: rgb(0 0 0 / 55%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11131b;
  --surface: #1a1d29;
  --surface-2: #242838;
  --ink: #e9ebf5;
  --muted: #9ba1ba;
  --line: #2f3448;
  --line-strong: #7d84a8;
  --accent: #8a94ff;
  --accent-ink: #11131b;
  --accent-soft: #2b3060;
  --user: #9aa4ff;
  --wrong: #ff6e73;
  --wrong-soft: #3a1f27;
  --cell: #1a1d29;
  --peer: #222639;
  --same: #353d75;
  --sel: #424c94;
  --clash: #4a2229;
  --flash: #8a94ff;
  --knob: #e9ebf5;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 3px 12px rgb(0 0 0 / 22%);
  --shadow-lg: 0 12px 40px rgb(0 0 0 / 55%);
  --accent-glow: 0 6px 18px -8px rgb(138 148 255 / 45%);
  --backdrop: rgb(0 0 0 / 55%);
}

/* ---------- 기본 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  touch-action: manipulation;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  word-break: keep-all;
  overflow-wrap: break-word;
}

button,
select {
  font: inherit;
  color: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.ic {
  flex: none;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.noscript {
  max-width: 460px;
  margin: 40px auto;
  padding: 20px;
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
  line-height: 1.7;
}

/* ---------- 앱 레이아웃 ---------- */
.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "status" "board" "controls";
  row-gap: 10px;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

/* ---------- 상단 바 ---------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-ic {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.brand-name {
  margin: 0;
  overflow: hidden;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.lang-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px 0 12px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s;
}

.lang-pill .ic {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.lang-pill .chev {
  width: 16px;
  height: 16px;
}

.lang-pill:active {
  transform: scale(0.96);
}

.lang-pill:has(.lang-select:focus-visible) {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.lang-name {
  white-space: nowrap;
}

/* 네이티브 select를 투명하게 덮어서 OS 기본 선택창을 씀 */
.lang-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.icon-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform 0.12s, background-color 0.15s, opacity 0.15s;
}

.icon-btn .ic {
  width: 21px;
  height: 21px;
}

.icon-btn.sm {
  width: 34px;
  height: 34px;
}

.icon-btn.sm .ic {
  width: 17px;
  height: 17px;
}

.icon-btn:active:not(:disabled) {
  transform: scale(0.9);
}

.icon-btn:disabled {
  opacity: 0.4;
}

/* ---------- 상태 줄 ---------- */
.status {
  grid-area: status;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  font-size: 14px;
}

.chip {
  display: inline-flex;
  justify-self: start;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.bars {
  display: inline-flex;
  flex: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.bars i {
  width: 3px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.28;
}

.bars i:nth-child(1) { height: 40%; }
.bars i:nth-child(2) { height: 60%; }
.bars i:nth-child(3) { height: 80%; }
.bars i:nth-child(4) { height: 100%; }

.bars[data-level="1"] i:nth-child(-n+1),
.bars[data-level="2"] i:nth-child(-n+2),
.bars[data-level="3"] i:nth-child(-n+3),
.bars[data-level="4"] i {
  opacity: 1;
}

.mistakes {
  justify-self: center;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: color 0.2s, background-color 0.2s;
}

.mistakes.bad {
  background: var(--wrong-soft);
  color: var(--wrong);
}

.chip.empty,
.mistakes.empty {
  visibility: hidden;
}

.clock {
  display: inline-flex;
  justify-self: end;
  align-items: center;
  gap: 6px;
}

.timer {
  min-width: 3.1em;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#pauseBtn .ic-play,
#pauseBtn[aria-pressed="true"] .ic-pause {
  display: none;
}

#pauseBtn[aria-pressed="true"] .ic-play {
  display: block;
}

#pauseBtn .ic-play {
  fill: currentColor;
}

/* ---------- 판 ---------- */
/* 남은 공간을 다 쓰고 정사각형 유지: 컨테이너 단위 (미지원 브라우저는 JS가 --bs를 px로 넣음) */
.board-wrap {
  grid-area: board;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  container-type: size;
}

.board-box {
  --bs: min(100cqw, 100cqh);
  position: relative;
  width: var(--bs);
  height: var(--bs);
}

/* 굵은 선 = 판 배경 + gap, 가는 선 = 상자 배경 + gap */
.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 2px;
  overflow: hidden;
  border: 2px solid var(--line-strong);
  border-radius: 12px;
  background: var(--line-strong);
  box-shadow: var(--shadow);
}

.box {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 1px;
  min-width: 0;
  min-height: 0;
  background: var(--line);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--cell);
  color: var(--user);
  font-size: calc(var(--bs) * 0.064);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: background-color 0.12s;
  cursor: pointer;
}

.cell .v {
  display: block;
  pointer-events: none;
}

.cell.given {
  color: var(--ink);
  font-weight: 600;
}

.cell.wrong {
  color: var(--wrong);
}

.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.clash { background: var(--clash); }
.cell.sel { background: var(--sel); }

/* 메모: 3×3 작은 숫자 */
.cell .n {
  position: absolute;
  inset: 4%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  color: var(--muted);
  font-size: calc(var(--bs) * 0.03);
  font-weight: 600;
  pointer-events: none;
}

.cell .n:empty {
  display: none;
}

.cell .n i {
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-style: normal;
  line-height: 1;
}

.cell .n i.hl {
  background: var(--accent);
  color: var(--accent-ink);
}

/* 반짝임 오버레이 (줄·칸·상자 완성, 승리 물결) */
.cell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--flash);
  opacity: 0;
  pointer-events: none;
}

.cell.flash::after {
  animation: cell-flash 0.62s ease-out var(--d, 0ms) both;
}

.cell.flash .v {
  animation: cell-bump 0.62s ease-out var(--d, 0ms) both;
}

.cell.shake .v {
  animation: cell-shake 0.42s ease;
}

.cell.pop .v {
  animation: cell-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.board.appear .cell .v,
.board.appear .cell .n {
  animation: cell-appear 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) calc(var(--w, 0ms) * 0.5) both;
}

@keyframes cell-flash {
  0% { opacity: 0; }
  30% { opacity: 0.32; }
  100% { opacity: 0; }
}

@keyframes cell-bump {
  0%, 100% { transform: none; }
  30% { transform: scale(1.2); }
}

@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-14%); }
  40% { transform: translateX(11%); }
  60% { transform: translateX(-7%); }
  80% { transform: translateX(4%); }
}

@keyframes cell-pop {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes cell-appear {
  from { transform: scale(0.55); opacity: 0; }
}

/* 일시정지 덮개: 숫자를 가림 */
.pause-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line), var(--shadow);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  animation: fade-in 0.2s ease-out;
}

.play-big {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--accent-glow);
  color: var(--accent-ink);
  transition: transform 0.12s;
}

.play-big .ic {
  width: 34px;
  height: 34px;
  margin-left: 5px;
  fill: currentColor;
  stroke-width: 1.5;
}

.play-big:active {
  transform: scale(0.92);
}

.pause-title {
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
}

.pause-sub {
  font-size: 14px;
  font-weight: 600;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@media (hover: hover) and (pointer: fine) {
  .cell:not(.sel):hover {
    box-shadow: inset 0 0 0 2px var(--accent-soft);
  }
}

/* ---------- 조작부 ---------- */
.controls {
  grid-area: controls;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 2px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.12s, color 0.15s, opacity 0.15s;
}

.tool-ic {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 38px;
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: background-color 0.15s, color 0.15s;
}

.tool-ic .ic {
  width: 22px;
  height: 22px;
}

.tool-l {
  max-width: 100%;
  overflow: hidden;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool:active:not(:disabled) {
  transform: scale(0.93);
}

.tool:active:not(:disabled) .tool-ic {
  background: var(--accent-soft);
}

.tool:disabled {
  opacity: 0.4;
}

/* 메모 켜짐/꺼짐: 아이콘 위 작은 스위치 (언어와 무관) */
#notesBtn[aria-pressed="true"] {
  color: var(--accent);
}

#notesBtn[aria-pressed="true"] .tool-ic {
  background: var(--accent-soft);
  color: var(--accent);
}

.switch-mini {
  position: absolute;
  right: -7px;
  bottom: -5px;
  width: 22px;
  height: 13px;
  border-radius: 999px;
  background: var(--line);
  box-shadow: 0 0 0 2px var(--bg);
  transition: background-color 0.15s;
}

.switch-mini::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--knob);
  box-shadow: 0 1px 2px rgb(0 0 0 / 25%);
  transition: transform 0.15s;
}

#notesBtn[aria-pressed="true"] .switch-mini {
  background: var(--accent);
}

#notesBtn[aria-pressed="true"] .switch-mini::after {
  background: var(--accent-ink);
  transform: translateX(9px);
}

.badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
  color: var(--accent-ink);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
}

.badge.zero {
  background: var(--muted);
  color: var(--surface);
}

/* 숫자 패드 */
.pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
}

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 58px;
  height: clamp(48px, 8.2vh, 66px);
  height: clamp(48px, 8.2dvh, 66px);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--accent);
  transition: transform 0.1s, background-color 0.15s, opacity 0.2s;
}

.key-d {
  font-size: 27px;
  font-weight: 600;
  line-height: 1;
}

.key-n {
  min-height: 11px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pad.notes .key-d {
  color: var(--ink);
  font-size: 21px;
  font-weight: 500;
}

.key:active:not(:disabled) {
  transform: scale(0.9);
  background: var(--accent-soft);
}

.key:disabled {
  opacity: 0.3;
  background: var(--surface-2);
  box-shadow: none;
}

@media (hover: hover) and (pointer: fine) {
  .key:hover:not(:disabled),
  .tool:hover:not(:disabled) .tool-ic {
    background: var(--accent-soft);
  }
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  transition: transform 0.12s, filter 0.15s, background-color 0.15s, opacity 0.15s;
}

.btn.primary {
  background: var(--accent);
  box-shadow: var(--accent-glow);
  color: var(--accent-ink);
}

.btn.sm {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 11px;
  font-size: 14px;
}

.btn.block {
  width: 100%;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    filter: brightness(1.06);
  }
}

.new-btn {
  width: 100%;
}

/* 토스트: 패드 위에 잠깐 */
.toast {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: var(--shadow-lg);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition: opacity 0.18s, transform 0.18s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 업데이트 배너 ---------- */
.banner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 50%;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(calc(100% - 24px), 520px);
  padding: 10px 10px 10px 16px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line);
  color: var(--ink);
  transform: translateX(-50%);
  animation: banner-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.banner-txt {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.banner-title {
  font-size: 15px;
  line-height: 1.3;
}

.banner-sub {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.banner .icon-btn {
  background: var(--surface-2);
  box-shadow: none;
}

.banner .btn {
  flex: none;
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translate(-50%, -24px);
  }
}

/* ---------- 시트 (휴대폰: 아래에서 올라옴 / 넓은 화면: 가운데 창) ---------- */
.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 0.25s;
}

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: calc(100% - 16px - env(safe-area-inset-top));
  border-radius: 24px 24px 0 0;
  outline: none;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-layer.open .backdrop {
  opacity: 1;
}

.sheet-layer.open .sheet {
  transform: none;
}

.grabber {
  flex: none;
  width: 38px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: var(--line);
}

.sheet-x {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  background: var(--surface-2);
  box-shadow: none;
}

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding:
    8px
    max(20px, env(safe-area-inset-right))
    calc(20px + env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

@media (min-width: 640px) and (min-height: 560px) {
  .sheet-layer {
    align-items: center;
  }

  .sheet {
    width: calc(100% - 48px);
    max-width: 480px;
    max-height: min(88vh, 780px);
    border-radius: 24px;
    opacity: 0;
    transform: translateY(14px) scale(0.97);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  }

  .sheet-layer.open .sheet {
    opacity: 1;
  }

  .grabber {
    display: none;
  }

  .sheet-body {
    padding: 22px 24px 24px;
  }
}

.sheet-title {
  margin: 6px 48px 4px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
}

/* 새 게임 */
.diffs {
  display: grid;
  gap: 10px;
}

.diff {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--surface-2);
  text-align: left;
  transition: transform 0.12s, background-color 0.15s;
}

.diff:active {
  transform: scale(0.98);
  background: var(--accent-soft);
}

@media (hover: hover) and (pointer: fine) {
  .diff:hover {
    background: var(--accent-soft);
  }
}

.diff .bars {
  gap: 3px;
  height: 20px;
  color: var(--accent);
}

.diff .bars i {
  width: 4px;
  border-radius: 2px;
}

.diff-txt {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.diff-name {
  font-size: 17px;
  font-weight: 700;
}

.diff-desc {
  color: var(--muted);
  font-size: 13.5px;
}

.diff-best {
  flex: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sheet-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.making {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 44px 0 36px;
  color: var(--muted);
  font-weight: 600;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3.5px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(1turn); }
}

/* 설정 */
.sec {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.sheet-title + .sec {
  margin-top: 10px;
}

.sec:last-child {
  padding-bottom: 4px;
}

.sec-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  background: var(--surface-2);
}

.seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.2;
  transition: background-color 0.15s, color 0.15s;
}

.seg button[aria-checked="true"] {
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  padding: 8px 0;
  font-size: 15.5px;
  text-align: left;
}

.switch {
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  transition: background-color 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--knob);
  box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
  transition: transform 0.2s;
}

.row[aria-checked="true"] .switch {
  background: var(--accent);
}

.row[aria-checked="true"] .switch::after {
  background: var(--accent-ink);
  transform: translateX(20px);
}

.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.stats th,
.stats td {
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.stats th {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.stats th:first-child,
.stats td:first-child {
  text-align: left;
}

.stats td:first-child {
  font-weight: 600;
}

.reset-btn {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--wrong);
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s;
}

.reset-btn.armed {
  background: var(--wrong-soft);
}

.ver {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 12px;
  font-weight: 600;
}

.ver code {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12.5px;
}

.upd-msg {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.install {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-2);
}

.install h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.install .btn {
  margin: 4px 0 6px;
}

.install p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
}

.install p.done {
  color: var(--accent);
  font-weight: 700;
}

/* 승리 / 게임 오버 */
.result {
  padding-top: 8px;
  text-align: center;
}

.result .emoji {
  margin: 8px 0 10px;
  font-size: 54px;
  line-height: 1;
  animation: cell-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.result .sheet-title {
  margin: 0 40px 4px;
}

.result .sub {
  margin-bottom: 18px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 14px;
  background: var(--surface-2);
}

.kpi span {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.kpi b {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.new-best {
  margin: 0 0 6px;
  color: var(--accent);
  font-weight: 700;
  animation: cell-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4) 0.2s both;
}

/* ---------- 작은 휴대폰 (세로) ---------- */
@media (max-height: 640px) and (orientation: portrait) {
  .app {
    row-gap: 8px;
  }

  .topbar {
    min-height: 40px;
  }

  .brand-name {
    font-size: 19px;
  }

  .tool-ic {
    height: 34px;
  }

  .tool {
    gap: 3px;
  }

  .key-d {
    font-size: 24px;
  }

  .btn,
  .new-btn {
    min-height: 44px;
  }
}

@media (max-width: 350px) {
  .lang-name {
    display: none;
  }

  .pad {
    gap: 4px;
  }

  .key-d {
    font-size: 23px;
  }
}

/* ---------- 휴대폰 가로: 왼쪽 판, 오른쪽 조작부 ---------- */
@media (orientation: landscape) and (max-height: 600px) {
  .app {
    grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "board top" "board status" "board controls";
    column-gap: 20px;
    row-gap: 8px;
    max-width: 980px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .status {
    grid-template-columns: auto 1fr auto;
    font-size: 13px;
  }

  .controls {
    justify-content: flex-end;
    min-height: 0;
    gap: 8px;
  }

  .pad {
    flex: 1 1 auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    min-height: 0;
    max-height: 230px;
  }

  .key {
    flex-direction: row;
    gap: 6px;
    height: auto;
    min-height: 34px;
  }

  .key-d {
    font-size: 23px;
  }

  .brand-name {
    font-size: 18px;
  }

  .btn,
  .new-btn {
    min-height: 42px;
  }
}

@media (orientation: landscape) and (max-height: 440px) {
  .topbar {
    min-height: 38px;
  }

  .lang-pill,
  .icon-btn {
    height: 36px;
  }

  .icon-btn {
    width: 36px;
  }

  .icon-btn.sm {
    width: 32px;
    height: 32px;
  }

  .tool-l {
    display: none;
  }

  .tool-ic {
    width: 100%;
    height: 36px;
  }

  .btn,
  .new-btn {
    min-height: 38px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

/* ---------- 움직임 줄이기 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
