/* 수식 신호등과 같은 흰 바탕, 칩, 모달. 타일만 숫자 게임용이다. */
:root {
  --bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #d3d6da;
  --tile-border: #e2e8f0;
  --tile-fill: #111827;
  --key: #e2e8f0;
  --key-text: #111827;
  --correct: #22c55e;
  --present: #eab308;
  --absent: #c4504a;
  --on: #ffffff;
  --present-ink: #1c1917;
  --modal: #ffffff;
  --overlay: rgba(107, 114, 128, 0.75);
  --toast-bad: #fecdd3;
  --toast-good: #bbf7d0;
  --toast-ink: #111827;
  --btn: #16a34a;
  --btn-ink: #ffffff;
  --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --chip: #f3f4f6;
  --chip-line: #e5e7eb;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #121213;
  --text: #f8fafc;
  --muted: #9ca3af;
  --line: #3a3a3c;
  --tile-border: #3a3a3c;
  --tile-fill: #d7dadc;
  --key: #9aa0a6;
  --key-text: #f8fafc;
  --correct: #22c55e;
  --present: #eab308;
  --absent: #9a4540;
  --on: #ffffff;
  --present-ink: #1c1917;
  --modal: #1a1a1b;
  --overlay: rgba(0, 0, 0, 0.72);
  --toast-bad: #7f1d1d;
  --toast-good: #14532d;
  --toast-ink: #f8fafc;
  --btn: #22c55e;
  --btn-ink: #052e16;
  --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.45);
  --chip: #1c1d21;
  --chip-line: #3a3a3c;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", ui-sans-serif, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: env(safe-area-inset-top) 8px 0;
  border-bottom: 1px solid var(--line);
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.brand { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[lang="en"] h1 { font-size: 0.92rem; }
.sig { display: flex; gap: 3px; flex: none; }
.sig-tile {
  width: 22px; height: 22px; border-radius: 4px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; line-height: 1;
}
.sig-tile.absent { background: var(--absent); color: var(--on); }
.sig-tile.correct { background: var(--correct); color: var(--on); }
.sig-tile.present { background: var(--present); color: var(--present-ink); }
.iconbtn {
  flex: none; width: 32px; height: 32px; border: 0; background: transparent;
  border-radius: 4px; display: grid; place-items: center; padding: 0;
}
.iconbtn:hover, .iconbtn:focus-visible { background: var(--key); outline: none; }
.meta { max-width: 560px; width: 100%; margin: 0 auto; padding: 6px 8px 0; text-align: center; color: var(--muted); }
.visitors {
  display: inline-block; max-width: 100%; margin: 0 0 6px; padding: 3px 10px;
  border: 1px solid var(--chip-line); border-radius: 999px; background: var(--chip);
  color: var(--muted); font-size: 0.68rem; font-weight: 700; line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
.visitors[hidden] { display: none; }
.status { display: grid; grid-template-columns: 1.25fr 0.85fr 0.95fr; gap: 6px; text-align: left; }
.status.is-play #chip-next, .status.is-create #chip-next { display: none; }
.status.is-play, .status.is-create { grid-template-columns: 1fr 1fr; }
.chip { background: var(--chip); border: 1px solid var(--chip-line); border-radius: 8px; padding: 5px 8px 4px; min-width: 0; }
.chip-k { display: flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.chip-v { display: block; margin-top: 1px; font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chip-slot .chip-v { white-space: normal; font-size: 12px; line-height: 1.25; }
.chip-v.num { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; font-size: 16px; letter-spacing: -0.04em; }
.modes { display: flex; justify-content: center; gap: 4px; margin-top: 2px; }
.modes button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 700; font-size: 0.8rem; padding: 4px 10px 6px; }
.modes button.on { color: var(--text); border-bottom-color: var(--text); }
.toast {
  position: relative; z-index: 5; width: max-content; max-width: min(92vw, 24rem);
  margin: 8px auto 0; background: var(--toast-bad); color: var(--toast-ink);
  border-radius: 4px; padding: 10px 14px; font-weight: 700; font-size: 0.9rem; text-align: center;
}
.toast.good { background: var(--toast-good); }
.toast[hidden] { display: none; }
main { position: relative; flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 560px; margin: 0 auto; padding: 16px 12px 8px; }
.stage { position: relative; min-height: 220px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.target {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 148px; padding: 8px 22px 10px; border-radius: 18px;
  border: 2px solid var(--line); background: var(--chip);
}
.target[hidden] { display: none; }
.target-k { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.target-v { font-size: clamp(2.4rem, 10vw, 3.4rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; min-height: 72px; }
.tile {
  width: clamp(64px, 18vw, 84px); height: clamp(64px, 18vw, 84px);
  border: 2px solid var(--tile-border); border-radius: 14px; background: var(--bg); color: var(--text);
  font-weight: 800; font-size: clamp(1.2rem, 5vw, 1.7rem); font-variant-numeric: tabular-nums;
  touch-action: manipulation;
}
.tile.made { background: var(--chip); }
.tile.on { border-color: var(--text); transform: translateY(-2px); }
.tile.near { box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.85); }
.tile.hot { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.9); }
.target.near { animation: glow 1.15s ease-in-out infinite; box-shadow: 0 0 0 4px rgba(234, 179, 8, 0.45); }
.target.hot { animation: glow 0.7s ease-in-out infinite; box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.55); }
.gate {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; padding: 20px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.gate[hidden] { display: none; }
.gate-note { margin: 0; max-width: 20rem; color: var(--text); font-size: 1rem; font-weight: 700; line-height: 1.45; text-align: center; }
.btn-start { min-width: 11rem; border: 0; border-radius: 14px; padding: 16px 36px; background: #111827; color: #fff; font-size: 1.4rem; font-weight: 800; }
html[data-theme="dark"] .btn-start { background: #f8fafc; color: #111827; }
.hint { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 0.85rem; min-height: 1.4em; }
.hint button { background: none; border: 0; color: var(--text); font-weight: 700; text-decoration: underline; padding: 0 0 0 4px; }
.expr, .expr-line { display: block; margin-top: 4px; font-weight: 800; color: var(--text); }
.expr-line { text-align: center; font-size: 1.05rem; margin-bottom: 8px; }
.controls { width: 100%; max-width: 560px; margin: 0 auto; padding: 4px 12px calc(12px + env(safe-area-inset-bottom)); }
body.is-waiting .controls { visibility: hidden; }
.ops { display: flex; gap: 8px; }
.op {
  flex: 1; height: 58px; border: 0; border-radius: 12px; background: var(--key); color: var(--key-text);
  font-size: 1.6rem; font-weight: 800; transition: opacity 180ms ease, transform 180ms ease;
  touch-action: manipulation;
}
.op.on { outline: 3px solid var(--text); outline-offset: 1px; }
.op.used { opacity: 0; transform: scale(0.82); pointer-events: none; }
.tools { display: flex; gap: 8px; margin-top: 8px; }
.tools button { flex: 1; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: transparent; font-weight: 800; }
.tools button:disabled { opacity: 0.4; }
.extra { max-width: 560px; width: 100%; margin: 0 auto; padding: 0 12px 8px; display: grid; gap: 8px; }
.extra[hidden] { display: none; }
.extra .btn, .extra .btn-ghost { margin-top: 0; }
.keycard { margin: 0 0 10px; padding: 14px 12px 12px; border: 2px solid #d4a017; border-radius: 14px; background: linear-gradient(180deg, #fff8e1, #f3d27a); text-align: center; }
.key-art { width: 132px; height: auto; display: block; margin: 0 auto 6px; }
.key-title { margin: 0; font-size: 1.15rem; font-weight: 800; color: #7c4a03; }
.key-body { margin: 8px 0 0; font-size: 0.98rem; font-weight: 700; line-height: 1.45; color: #6b3e06; }
html[data-theme="dark"] .keycard { background: linear-gradient(180deg, #3b2a08, #1c1404); border-color: #f6d56a; }
html[data-theme="dark"] .key-title, html[data-theme="dark"] .key-body { color: #fde68a; }
.device-note { margin: 0 0 10px; padding: 12px; border-radius: 12px; background: #fff7ed; color: #9a3412; font-weight: 800; line-height: 1.45; text-align: center; }
html[data-theme="dark"] .device-note { background: #431407; color: #fdba74; }
.thanks { display: block; margin: 10px 0 2px; padding: 12px; border: 2px solid #f59e0b; border-radius: 12px; background: #fffbeb; color: #78350f; text-decoration: none; text-align: center; }
.thanks-msg { display: block; font-size: 1.02rem; line-height: 1.45; font-weight: 700; }
.thanks-handle { display: inline-block; margin-top: 8px; padding: 4px 10px; border-radius: 999px; background: #111827; color: #fff; font-size: 0.95rem; font-weight: 800; }
html[data-theme="dark"] .thanks { background: #3b2a12; border-color: #fbbf24; color: #fef3c7; }
html[data-theme="dark"] .thanks-handle { background: #fbbf24; color: #1c1917; }
.promos { margin-top: 8px; }
.promo, .pop-item, .pop-menu {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 6px; padding: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--text);
  text-align: left; text-decoration: none; font: inherit; font-weight: 700;
}
.promo { display: block; margin: 8px 0 2px; padding: 12px; border: 2px solid #111827; border-radius: 12px; background: #f8fafc; color: #111827; }
.mbody a.promo { color: #111827; }
.promo-row { display: flex; align-items: center; gap: 10px; text-align: left; }
.promo-copy { flex: 1; min-width: 0; }
.promo-name { display: block; font-size: 1.02rem; font-weight: 800; }
.promo-tag { display: block; margin-top: 2px; font-size: 0.86rem; font-weight: 700; line-height: 1.35; color: #374151; }
.promo-open { flex: none; padding: 6px 10px; border-radius: 999px; background: #111827; color: #fff; font-size: 0.85rem; font-weight: 800; }
html[data-theme="dark"] .promo { background: #1c1d21; border-color: #e5e7eb; color: #f8fafc; }
html[data-theme="dark"] .mbody a.promo, html[data-theme="dark"] .promo-name { color: #f8fafc; }
html[data-theme="dark"] .promo-tag { color: #d1d5db; }
html[data-theme="dark"] .promo-open { background: #f8fafc; color: #111827; }
.pop { position: fixed; inset: 0; z-index: 45; background: transparent; }
.pop-sheet {
  position: absolute; top: calc(env(safe-area-inset-top) + 52px); right: 8px;
  width: min(280px, calc(100vw - 16px)); padding: 12px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--bg); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
}
.pop-kicker { margin: 0 0 8px; font-weight: 800; color: var(--text); }
.pop-ad { border-style: dashed; justify-content: center; min-height: 68px; text-align: center; }
.ad-copy { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 100%; font-weight: 800; line-height: 1.35; }
#modal[hidden] { display: none; }
#modal { position: fixed; inset: 0; z-index: 30; overflow: auto; }
.overlay { position: fixed; inset: 0; background: var(--overlay); }
.panel { position: relative; z-index: 1; width: calc(100% - 2rem); max-width: 24rem; margin: 8vh auto 2rem; background: var(--modal); color: var(--text); border-radius: 8px; box-shadow: var(--shadow); padding: 1.35rem 1.15rem 1.25rem; }
.close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border: 0; background: transparent; font-size: 1.4rem; line-height: 1; border-radius: 4px; }
.mtitle { margin: 0 1.5rem 0.6rem; text-align: center; font-size: 1.125rem; font-weight: 500; }
.mbody { color: var(--muted); font-size: 0.875rem; line-height: 1.55; }
.mbody p { margin: 0 0 0.55rem; }
.mbody .ink { color: var(--text); }
.stats { display: flex; justify-content: center; gap: 4px; margin: 4px 0 12px; }
.stat { flex: 1; text-align: center; }
.stat b { display: block; color: var(--text); font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.stat span { font-size: 0.72rem; }
.rankline { margin: 4px 0; font-weight: 800; text-align: center; color: var(--text); }
.lb { list-style: none; margin: 6px 0 0; padding: 0; }
.lb li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); color: var(--text); font-size: 0.9rem; }
.lb .me { font-weight: 700; background: color-mix(in srgb, var(--correct) 22%, transparent); border-radius: 4px; padding-left: 6px; padding-right: 6px; }
.lb .num { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.who { display: inline-flex; align-items: center; min-width: 0; gap: 0.2em; }
.flag { display: inline-grid; place-items: center; width: 1.35em; flex: none; line-height: 1; }
.flag-code { display: none; font-size: 0.68rem; font-weight: 800; }
.ctabs { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0 4px; }
.ctab { flex: none; border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: 4px 10px; font-weight: 800; }
.ctab.on { background: var(--text); color: var(--bg); }
.hall-who { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.hall-round { font-weight: 800; }
.hall-players { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.lb.hall li { align-items: flex-start; }
.btn, .btn-ghost { display: block; width: 100%; margin-top: 8px; border-radius: 6px; padding: 10px 14px; font-weight: 700; font-size: 0.95rem; text-align: center; text-decoration: none; }
.btn { border: 0; background: var(--btn); color: var(--btn-ink); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-boast { background: #111827; color: #fff; font-size: 1.05rem; padding: 14px; }
html[data-theme="dark"] .btn-boast { background: #f8fafc; color: #111827; }
.nick { width: 100%; margin-top: 8px; font-size: 16px; padding: 8px 10px; border-radius: 6px; border: 2px solid var(--line); background: var(--bg); }
.langs { display: flex; gap: 6px; margin: 6px 0 12px; }
.lang { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 8px 4px; font-weight: 700; }
.lang.on { background: var(--text); color: var(--bg); }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.setrow small { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 3px; }
.toggle { width: 56px; height: 32px; flex: none; border: 0; border-radius: 999px; background: #d1d5db; padding: 4px; }
.toggle.on { background: #4ade80; }
.toggle i { display: block; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.2s ease; }
.toggle.on i { transform: translateX(24px); }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mcard { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.mcard b { display: block; color: var(--text); font-size: 1.05rem; }
.mcard span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.72rem; }
.mhead { margin: 14px 0 6px; color: var(--text); font-size: 0.95rem; font-weight: 800; }
.mnote { margin: 0 0 8px; color: var(--muted); font-size: 0.75rem; }
.celebrate { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
@keyframes merge-in {
  0% { transform: scale(0.55); opacity: 0.35; }
  62% { transform: scale(1.14); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes undo-in {
  0% { transform: scale(0.86); }
  100% { transform: scale(1); }
}
@keyframes hit {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  40% { transform: scale(1.16); box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
  100% { transform: scale(1); }
}
@keyframes glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}
.tile.born { animation: merge-in 280ms cubic-bezier(.2, 1.35, .4, 1); }
.tiles.undo .tile { animation: undo-in 240ms ease; }
.tile.hit, .target.hit { animation: hit 480ms ease; }
@media (prefers-reduced-motion: reduce) {
  .tile.born, .tiles.undo .tile, .tile.hit, .target.hit, .target.near, .target.hot, .op, .toggle i {
    animation: none; transition: none;
  }
  .celebrate { display: none; }
}
