:root {
  --cream-50: #fff6ef;
  --cream-100: #ffeadb;
  --berry-500: #e2456b;
  --berry-600: #c7325a;
  --mint-400: #4fc9a8;
  --mint-500: #2fae8c;
  --cocoa-900: #3a2420;
  --cocoa-600: #7a5a52;
  --cocoa-300: #c9b3aa;
  --white: #ffffff;

  --color-bg: var(--cream-50);
  --color-surface: var(--white);
  --color-soft: var(--cream-100);
  --color-text: var(--cocoa-900);
  --color-muted: var(--cocoa-600);
  --color-line: var(--cocoa-300);
  --color-accent: var(--berry-500);
  --color-accent-strong: var(--berry-600);
  --color-good: var(--mint-500);
  --color-good-soft: var(--mint-400);
  --radius: 18px;
  --shadow: 0 6px 20px rgb(58 36 32 / 0.08);
  font-family: "Pretendard", "SUIT", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", "Noto Naskh Arabic", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1f1715;
    --color-surface: #2b201d;
    --color-soft: #3a2b27;
    --color-text: #fbeee6;
    --color-muted: #c9b3aa;
    --color-line: #5a4640;
    --shadow: 0 6px 20px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }

.app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.badge {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--color-accent); color: var(--white); font-size: 15px; font-weight: 900;
}
.langs { display: flex; gap: 4px; background: var(--color-soft); padding: 3px; border-radius: 999px; }
.lang {
  border: 0; background: transparent; color: var(--color-muted); font: inherit; font-size: 13px;
  padding: 6px 10px; border-radius: 999px; cursor: pointer; min-height: 32px;
}
.lang[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); font-weight: 700; box-shadow: var(--shadow); }

.screen { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-top: 12px; }
.hero { font-size: 44px; margin: 24px 0 0; letter-spacing: -0.02em; color: var(--color-accent); }
h2 { margin: 0; text-align: center; }
.muted { color: var(--color-muted); margin: 0; text-align: center; }
#lobby .muted { text-align: start; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--color-muted); margin-top: 12px; }
input {
  font: inherit; font-size: 17px; padding: 14px 16px; border-radius: 14px; width: 100%;
  border: 1.5px solid var(--color-line); background: var(--color-surface); color: var(--color-text);
}
input:focus { outline: none; border-color: var(--color-accent); }
#code { letter-spacing: 0.25em; font-weight: 700; text-transform: uppercase; }
#code:placeholder-shown { letter-spacing: normal; font-weight: 400; text-transform: none; }

.btn {
  font: inherit; font-size: 17px; font-weight: 700; padding: 14px 18px; border-radius: 14px;
  border: 1.5px solid var(--color-line); background: var(--color-surface); color: var(--color-text);
  cursor: pointer; min-height: 52px; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--white); }
.btn.primary:active { background: var(--color-accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--color-muted); font-weight: 500; margin-top: auto; }

.row { display: flex; gap: 8px; }
.row > input { flex: 1; min-width: 0; }
.row > .btn { flex: 1; }
#lobby .row > .btn { flex: 0 0 auto; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--color-muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--color-line); }

.rules { margin-top: auto; font-size: 14px; line-height: 1.6; color: var(--color-muted); background: var(--color-soft); padding: 14px 16px; border-radius: var(--radius); }

/* waiting */
#waiting { align-items: stretch; justify-content: center; text-align: center; }
.pulse { width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 50%; background: var(--color-accent); opacity: 0.85; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.82); opacity: 0.45; } }
.code-box { font-size: 40px; font-weight: 900; letter-spacing: 0.2em; padding: 18px; border-radius: var(--radius); background: var(--color-surface); box-shadow: var(--shadow); }

/* game */
.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.player {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 16px;
  background: var(--color-surface); border: 2px solid transparent; transition: border-color .2s, transform .2s; min-width: 0;
}
.player.active { border-color: var(--color-accent); transform: translateY(-2px); }
.pname { font-size: 14px; color: var(--color-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pscore { font-size: 26px; font-weight: 900; }
.vs { font-size: 22px; font-weight: 900; color: var(--color-muted); }

.counter { display: grid; place-items: center; margin-top: 4px; }
.ring {
  --p: 0;
  width: 190px; height: 190px; border-radius: 50%; display: grid; place-items: center; align-content: center;
  background: conic-gradient(var(--color-good) calc(var(--p) * 360deg), var(--color-soft) 0);
  position: relative; transition: background .3s;
}
.ring::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; background: var(--color-bg); }
.ring > * { position: relative; }
.ring.danger { background: conic-gradient(var(--color-accent) calc(var(--p) * 360deg), var(--color-soft) 0); }
#countNum { font-size: 64px; font-weight: 900; line-height: 1; }
.ring small { color: var(--color-muted); font-size: 15px; }

#game.over .track { display: none; }
#game.over .ring { width: 130px; height: 130px; }
#game.over #countNum { font-size: 44px; }
.last { text-align: center; margin: 0; min-height: 1.4em; font-weight: 600; }

.track { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.dot {
  font-size: 12px; text-align: center; padding: 6px 0; border-radius: 9px;
  background: var(--color-soft); color: var(--color-muted); font-variant-numeric: tabular-nums;
}
.dot.done { background: var(--color-good-soft); color: var(--white); }
.dot.fresh { background: var(--color-good); color: var(--white); font-weight: 800; }
.dot.end { background: var(--color-accent); color: var(--white); font-weight: 900; }

.status { text-align: center; margin: 0; font-size: 17px; font-weight: 700; color: var(--color-muted); }
.status.mine { color: var(--color-accent); }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.step {
  font: inherit; font-size: 17px; font-weight: 800; min-height: 64px; white-space: nowrap; padding: 0 4px; border-radius: 16px; cursor: pointer;
  border: 0; background: var(--color-accent); color: var(--white); box-shadow: var(--shadow);
}
.step:active { transform: scale(0.96); }
.step:disabled { background: var(--color-soft); color: var(--color-line); box-shadow: none; cursor: default; }

.result {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: var(--radius);
  background: var(--color-surface); box-shadow: var(--shadow); text-align: center;
  border: 2px solid var(--color-good);
}
.result.lost { border-color: var(--color-accent); }
.result-title { margin: 0; font-size: 19px; font-weight: 800; }
.penalty { background: var(--color-soft); border-radius: 14px; padding: 10px 12px; }
.penalty small { color: var(--color-muted); }
.penalty p { margin: 4px 0 0; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--color-text); color: var(--color-bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; max-width: calc(100% - 32px); text-align: center; z-index: 10;
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
