:root {
  color-scheme: light;
  --bg: #f4ead8;
  --card: #fffaf1;
  --ink: #3b2a1a;
  --muted: #8a7560;
  --line: #e6d6bb;
  --primary: #e8743b;
  --primary-ink: #fff;
  --primary-dark: #c95a24;
  --teal: #2a7f8f;
  --ok: #2a9d8f;
  --danger: #d1495b;
  --radius: 16px;
  --shadow: 0 2px 0 rgba(90, 60, 20, .08), 0 6px 18px rgba(90, 60, 20, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3, .mode-btn b, .big-btn, .room-code, .result-emoji + h2 { font-family: "Jua", "Noto Sans KR", sans-serif; font-weight: 400; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- book button & toasts ---------- */
.book-btn {
  position: fixed; top: max(10px, env(safe-area-inset-top)); right: 12px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--teal); color: #fff; box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.book-btn:active { transform: scale(.94); }
.conn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 70; text-align: center;
  background: var(--danger); color: #fff; padding: 6px; font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px);
  background: rgba(40, 28, 16, .92); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 15px; z-index: 90; opacity: 0; pointer-events: none; transition: .25s;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- pages ---------- */
.page { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }
.bar { display: flex; align-items: center; gap: 8px; min-height: 48px; padding-right: 52px; margin-bottom: 8px; }
.bar h2 { margin: 0; font-size: 22px; }
.back { border: 0; background: none; color: var(--muted); padding: 8px 4px; font-size: 15px; white-space: nowrap; }

.hero { text-align: center; padding: 36px 0 18px; }
.logo { width: 132px; }
.hero h1 { font-size: 46px; margin: 4px 0 4px; letter-spacing: 1px; }
.sub { color: var(--muted); margin: 0; }
.mode-list { display: grid; gap: 12px; margin-top: 18px; }
.mode-btn {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: 20px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.mode-btn:active { transform: translateY(1px); }
.mode-btn b { display: block; font-size: 22px; }
.mode-btn small { color: var(--muted); }
.mode-ico { font-size: 30px; width: 44px; text-align: center; }
.foot { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 26px; }
.foot a { color: var(--teal); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 10px; font-size: 20px; }
.card h4 { margin: 0; font-size: 16px; }
.card.center { text-align: center; }
.lbl { display: block; font-weight: 700; font-size: 14px; margin: 12px 0 6px; }
.note { font-weight: 400; color: var(--muted); }
.help { color: var(--muted); font-size: 13.5px; margin: 8px 0 0; }

.btn {
  border: 2px solid var(--line); background: #fff; border-radius: 12px;
  padding: 10px 14px; font-weight: 700; min-height: 44px;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.big-btn {
  display: block; width: 100%; border: 0; border-radius: 18px; padding: 16px; font-size: 22px;
  background: var(--card); box-shadow: var(--shadow);
}
.big-btn small { display: block; font-family: "Noto Sans KR", sans-serif; font-size: 13px; opacity: .85; }
.big-btn.primary { background: var(--primary); color: #fff; }
.big-btn.sticky { position: sticky; bottom: 12px; margin-top: 16px; z-index: 5; }
.big-btn:active { transform: translateY(1px); }

/* chips & radio cards */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; font-weight: 500; min-height: 40px; display: inline-flex; align-items: center; gap: 6px;
}
.chips button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips button:disabled { opacity: .35; }
.grid-chips svg { width: 22px; height: 20px; fill: #e9c48a; stroke: #9b6a35; stroke-width: 2; }
.grid-chips button.on svg { fill: #fff; stroke: #fff; }
.radio-cards { display: grid; gap: 8px; }
.radio-cards button {
  display: flex; gap: 12px; align-items: center; text-align: left;
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 12px;
}
.radio-cards button b { min-width: 56px; font-size: 17px; }
.radio-cards button span { color: var(--muted); font-size: 14px; }
.radio-cards button.on { border-color: var(--primary); background: #fff1e8; }
.radio-cards button.on b { color: var(--primary-dark); }
.radio-cards button::before {
  content: ""; flex: 0 0 18px; height: 18px; border-radius: 5px; border: 2px solid var(--line); background: #fff;
}
.radio-cards button.on::before { background: var(--primary); border-color: var(--primary); box-shadow: inset 0 0 0 3px #fff; }

.sub-opt { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.sub-opt input, .size-row input {
  width: 72px; padding: 8px; border: 2px solid var(--line); border-radius: 10px; text-align: center; background: #fff;
}
.sub-box { margin-top: 6px; padding-top: 4px; }
.size-row { display: flex; align-items: center; gap: 8px; }
.dim { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.dim input:disabled { opacity: .45; }
.times { color: var(--muted); font-size: 18px; }
.size-opts { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.shape-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.shape-list .empty { color: var(--muted); font-size: 14px; }
.shape-item { text-align: center; font-size: 12px; color: var(--muted); }
.shape-item canvas { width: 72px; height: 72px; background: #fff; border: 1px solid var(--line); border-radius: 12px; display: block; }
.orient-preview { margin-top: 10px; }
.orient-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.orient-row > span { font-size: 13px; color: var(--muted); width: 100%; }
.orient-row canvas { width: 40px; height: 40px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* online */
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1; min-width: 0; font-size: 22px; letter-spacing: 6px; text-align: center; padding: 8px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.list-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 6px; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.room-list li {
  display: flex; align-items: center; gap: 8px; border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 6px 6px 6px 12px;
}
.room-list .rinfo { flex: 1; min-width: 0; font-size: 14px; }
.room-list .rinfo b { font-size: 16px; }
.room-list .rinfo small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-list .gear { border: 0; background: #f3e8d6; border-radius: 10px; width: 40px; height: 40px; font-size: 18px; }
.room-list .empty { justify-content: center; color: var(--muted); border-style: dashed; padding: 14px; }
.room-code { font-size: 64px; letter-spacing: 10px; color: var(--primary-dark); margin: 6px 0; }
.pill { display: inline-block; background: #f3e8d6; border-radius: 999px; padding: 4px 12px; font-size: 14px; margin: 4px 0; }
.pill.small { font-size: 12px; padding: 2px 10px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 14px 0; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }
.summary { text-align: left; font-size: 14px; }
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; }
.summary dt { font-weight: 700; white-space: nowrap; }
.summary dd { margin: 0; color: var(--muted); }
.summary .thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.summary canvas { width: 48px; height: 48px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- game ---------- */
.game { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.game-top {
  display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 64px 0 10px; min-height: 52px;
}
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 10px; }
.player {
  display: flex; align-items: center; gap: 8px; background: var(--card); border: 2px solid var(--line);
  border-radius: 14px; padding: 6px 10px; min-width: 0; transition: .2s;
}
.player.turn { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(232, 116, 59, .25); }
.player.off { opacity: .55; }
.stone { flex: 0 0 22px; height: 22px; border-radius: 50%; }
.stone.b { background: radial-gradient(circle at 35% 30%, #777, #0a0a0a); }
.stone.w { background: radial-gradient(circle at 35% 30%, #fff, #d0d0d0); border: 1px solid #999; }
.pinfo { flex: 1; min-width: 0; line-height: 1.2; }
.pinfo b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinfo small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; }
.clock.low { color: var(--danger); animation: blink 1s infinite; }
.status { text-align: center; font-size: 15px; padding: 4px 12px 6px; min-height: 30px; }
.status b { color: var(--primary-dark); }
.board-wrap { position: relative; flex: 1; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.zoom { position: absolute; right: 10px; bottom: 10px; display: grid; gap: 6px; }
.zoom button {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 250, 241, .92);
  font-size: 20px; box-shadow: var(--shadow);
}
.float-result {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); border: 0; border-radius: 999px;
  background: var(--primary); color: #fff; padding: 8px 18px; font-weight: 700; box-shadow: var(--shadow);
}
.overlay-msg { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(244, 234, 216, .8); text-align: center; }
.overlay-msg b { display: block; font-size: 18px; }
.overlay-msg small { color: var(--muted); }
.actions {
  display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
}
.actions .btn { min-height: 52px; }
.btn.okay { background: var(--ok); border-color: var(--ok); color: #fff; font-size: 20px; font-family: "Jua", sans-serif; font-weight: 400; }
.btn.okay:not(:disabled) { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(42, 157, 143, .5); } 50% { box-shadow: 0 0 0 8px rgba(42, 157, 143, 0); } }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(40, 28, 16, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 600px; border-radius: 22px 22px 0 0; max-height: 92dvh;
  display: flex; flex-direction: column; box-shadow: 0 -6px 30px rgba(0, 0, 0, .2); animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet.tall { height: 92dvh; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; border-bottom: 1px solid var(--line); }
.sheet header h2 { margin: 0; font-size: 21px; }
.x { border: 0; background: #f3e8d6; width: 38px; height: 38px; border-radius: 50%; font-size: 16px; }
.sheet-body { padding: 12px 16px 20px; overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.book h3 { margin: 18px 0 6px; font-size: 19px; color: var(--teal); }
.book p, .book li { font-size: 15px; }
.book ul, .book ol { padding-left: 20px; margin: 0; }
.book li { margin-bottom: 6px; }
#book-current .card { margin-top: 0; }

.editor-body { display: flex; flex-direction: column; }
.shape-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.shape-tabs button { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.shape-tabs button.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.editor-canvas-wrap { position: relative; flex: 1; min-height: 240px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
#editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.sheet.result { text-align: center; padding: 22px 18px max(18px, env(safe-area-inset-bottom)); }
.result-emoji { font-size: 56px; line-height: 1; }
.sheet.result h2 { font-size: 34px; margin: 6px 0 4px; }
.sheet.result p { margin: 4px 0 12px; color: var(--muted); }
.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-btns.row { grid-template-columns: 1fr 1fr; }
.sheet.small { padding: 22px 18px max(18px, env(safe-area-inset-bottom)); text-align: center; }
.sheet.small p { font-size: 17px; margin: 0 0 16px; }

@media (min-width: 700px) {
  .modal { align-items: center; }
  .sheet { border-radius: 22px; }
  .sheet.tall { height: 86vh; }
}

/* ---------- presets & folded rules ---------- */
.help.top { margin: -4px 0 10px; }
.preset-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px; min-width: 0;
}
.preset canvas { width: 100%; height: 44px; }
.preset b { font-size: 15px; line-height: 1.25; }
.preset small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.preset.on { border-color: var(--primary); background: #fff1e8; }
.preset:active { transform: translateY(1px); }
.fold { padding: 0; }
.fold-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 0; background: none; padding: 16px; text-align: left;
}
.fold-head b { display: block; font-family: "Jua", sans-serif; font-weight: 400; font-size: 20px; }
.fold-head small { display: block; color: var(--muted); font-size: 13.5px; }
.fold-head .chev { font-size: 20px; color: var(--muted); transition: transform .2s; }
.fold-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.fold-body { padding: 0 16px 16px; border-top: 1px dashed var(--line); }
.fold-body h4 { font-size: 16px; margin: 16px 0 8px; }
.preset:last-child:nth-child(odd) { grid-column: 1 / -1; }
