/* 스밋코구라시 파스텔 — oishi(sss-webtoon-hunter) 팔레트 */
:root {
  --bg: #faf5ec; --panel: #fffdf8; --panel2: #f2e9da; --line: #e3d6c1;
  --fg: #5f5247; --dim: #87735f; --accent: #b4622f; --warn: #c25f5f;
  --hover: #f6eee0; --shadow: rgba(120,100,80,.18);
  --t1: #e8b9a0; --t2: #bcd3c4; --t3: #c9d4e6; --t4: #ded0e6;

  --grid: #a08b74;          /* 보드 굵은 선 */
  --peer: #f6eee0;
  --same: #f3d9c9;
  --selected: #e8b9a0;
  --user: #5878a8;
  --wrong-bg: #f7dcdc;

  --bw: min(calc(100vw - 12px), 520px, calc(100vh - 320px));
}
:root:not([data-theme="light"]) { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #2b2521; --panel: #342d28; --panel2: #3e3630; --line: #4b4139;
    --fg: #ece1d1; --dim: #a8967f; --accent: #e8ab7c; --warn: #e09b9b;
    --hover: #443b33; --shadow: rgba(0,0,0,.5);
    --t1: #7d5443; --t2: #42604f; --t3: #41506b; --t4: #544365;
    --grid: #7a6a58; --peer: #3e3630; --same: #5a4237; --selected: #7d5443;
    --user: #a9bde0; --wrong-bg: #5a3434;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #2b2521; --panel: #342d28; --panel2: #3e3630; --line: #4b4139;
  --fg: #ece1d1; --dim: #a8967f; --accent: #e8ab7c; --warn: #e09b9b;
  --hover: #443b33; --shadow: rgba(0,0,0,.5);
  --t1: #7d5443; --t2: #42604f; --t3: #41506b; --t4: #544365;
  --grid: #7a6a58; --peer: #3e3630; --same: #5a4237; --selected: #7d5443;
  --user: #a9bde0; --wrong-bg: #5a3434;
}
@supports (height: 100dvh) {
  :root {
    --bw: min(calc(100vw - 12px), 520px,
      calc(100dvh - 320px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  font-family: "Pretendard", "Hiragino Kaku Gothic ProN", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color: var(--fg);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- 테마 토글 ---------- */
.theme {
  display: inline-flex;
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
  background: var(--panel);
}
.theme button {
  color: var(--dim);
  font-size: 13px; padding: 6px 14px; line-height: 1.2;
}
.theme button[aria-pressed="true"] { background: var(--t1); color: var(--fg); font-weight: 700; }
.theme button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- 홈 ---------- */
#home { justify-content: center; gap: 28px; padding-left: 24px; padding-right: 24px; position: relative; }
#home .theme { position: absolute; top: calc(env(safe-area-inset-top) + 16px); right: 16px; }
.logo { font-size: 44px; font-weight: 900; margin: 0 0 8px; letter-spacing: 2px; color: var(--fg); }
.menu { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }
.menu-btn {
  width: 100%; max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  font-size: 22px; font-weight: 800;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform .08s;
}
.menu-btn[data-diff="easy"]   { background: var(--t2); }
.menu-btn[data-diff="medium"] { background: var(--t3); }
.menu-btn[data-diff="hard"]   { background: var(--t4); }
.menu-btn[data-diff="expert"] { background: var(--t1); }
.menu-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--shadow); }
.menu-btn.continue { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--accent); }
.menu-btn.continue small { font-size: 14px; font-weight: 600; color: var(--dim); }

/* ---------- 상단 ---------- */
.top {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 12px 6px;
  gap: 10px;
}
.round-btn {
  width: 54px; height: 54px; flex: none;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--accent);
  display: grid; place-items: center;
  box-shadow: 0 3px 0 var(--shadow);
}
.round-btn svg { width: 28px; height: 28px; }
.diff-title { margin: 0; font-size: 24px; font-weight: 900; color: var(--fg); letter-spacing: 1px; }

/* ---------- 보드 ---------- */
.board {
  width: var(--bw); height: var(--bw);
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 4px solid var(--grid);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 2px 6px var(--shadow);
  flex: none;
}
.cell {
  position: relative;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: grid; place-items: center;
  font-size: calc(var(--bw) / 9 * .62);
  line-height: 1;
  color: var(--fg);
  cursor: pointer;
}
.cell.c2, .cell.c5 { border-right: 2px solid var(--grid); }
.cell.c8 { border-right: 0; }
.cell.r2, .cell.r5 { border-bottom: 2px solid var(--grid); }
.cell.r8 { border-bottom: 0; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--selected); }
.cell.user { color: var(--user); }
.cell.wrong { color: var(--warn); }
.cell.wrong.selected, .cell.wrong.same { background: var(--wrong-bg); }
.cell.pop .v { animation: pop .22s ease-out; }
@keyframes pop { 0% { transform: scale(.5); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

.notes {
  position: absolute; inset: 1px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: calc(var(--bw) / 9 * .27);
  color: var(--dim);
  font-weight: 600;
}
.notes span { display: grid; place-items: center; }
.notes span.hl { color: var(--accent); font-weight: 900; }

/* ---------- 도구 ---------- */
.tools {
  width: 100%;
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding: 14px 4px 4px;
}
.tool { position: relative; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tool i {
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--panel2);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: transform .08s, opacity .15s;
}
.tool i svg { width: 26px; height: 26px; color: var(--fg); }
.tool span { font-size: 12px; font-weight: 800; color: var(--dim); white-space: nowrap; }
.tool:active i { transform: scale(.9); }
.tool:disabled { cursor: default; }
.tool:disabled i { opacity: .4; }
.tool em {
  position: absolute; top: -6px; right: calc(50% - 38px);
  font-style: normal; font-size: 12px; font-weight: 900;
  background: var(--panel); color: var(--dim);
  border: 1px solid var(--line);
  padding: 1px 7px; border-radius: 10px;
}
#t-note.on i { background: var(--t1); border-color: var(--t1); }
#t-note.on em { background: var(--t1); color: var(--fg); border-color: var(--t1); }
#t-auto i { background: var(--t2); border-color: var(--t2); }
#t-single i { background: var(--t3); border-color: var(--t3); }
#t-hint i { background: var(--t4); border-color: var(--t4); }

/* ---------- 숫자 패드 ---------- */
.pad {
  width: 100%;
  display: grid; grid-template-columns: repeat(9, 1fr);
  gap: 4px; padding: 10px 6px 14px;
}
.pad button {
  height: 66px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 40px; font-weight: 400;
  color: var(--fg);
  transition: background .1s;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.pad button:active { background: var(--t1); }
.pad button.done { visibility: hidden; }
.pad.note-mode button { font-size: 28px; color: var(--dim); background: var(--panel2); opacity: .7; }
.pad.note-mode button.noted {
  background: var(--t1); border-color: var(--accent);
  color: var(--fg); font-weight: 800; opacity: 1;
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---------- 모달/토스트 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(40,30,20,.45);
  display: grid; place-items: center;
  padding: 24px;
}
.modal-box {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line);
  width: 100%; max-width: 340px;
  border-radius: 22px;
  padding: 26px 22px 20px;
  text-align: center;
  box-shadow: 0 8px 24px var(--shadow);
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.modal-box h2 { margin: 0 0 8px; font-size: 26px; font-weight: 900; }
.modal-box p { margin: 0 0 20px; font-size: 15px; color: var(--dim); line-height: 1.5; white-space: pre-line; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions button {
  padding: 14px; border-radius: 14px; font-size: 17px; font-weight: 800;
  background: var(--t1); color: var(--fg);
}
.modal-actions button.secondary { background: var(--panel2); color: var(--dim); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--fg); color: var(--bg);
  padding: 10px 18px; border-radius: 20px;
  font-size: 14px; font-weight: 700;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .top { padding-top: 12px; }
  .round-btn { width: 46px; height: 46px; }
  .tool i { width: 42px; height: 42px; }
  .pad button { height: 54px; font-size: 34px; }
  :root { --bw: min(calc(100vw - 12px), 520px, calc(100vh - 280px)); }
}
@supports (height: 100dvh) {
  @media (max-height: 700px) {
    :root { --bw: min(calc(100vw - 12px), 520px, calc(100dvh - 280px)); }
  }
}
