:root {
  --bg: #0d1420;
  --panel: #152030;
  --line: #2b3b50;
  --text: #e8eef5;
  --muted: #93a4b8;
  --p0: #46d6c4;
  --p1: #ffb547;
  --danger: #ff5d73;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: safe center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(8, 13, 21, 0.78);
  z-index: 5;
}

.panel {
  width: min(460px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(34px, 8vw, 46px); line-height: 1.05; letter-spacing: 0.01em; }
.eyebrow { color: var(--p0); font-size: 14px; font-weight: 600; }
.lead { color: var(--muted); }
.msg { color: var(--danger); min-height: 1.5em; font-size: 14px; }
.msg:empty { display: none; }
.msg.busy { color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--text);
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
input:focus-visible, .btn:focus-visible, .mute:focus-visible { outline: 2px solid var(--p0); outline-offset: 2px; }

.btn {
  min-height: 44px;
  padding: 8px 16px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  background: #213044;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover { background: #2a3c54; }
.btn.primary { color: #06201d; background: var(--p0); border-color: var(--p0); }
.btn.primary:hover { background: #6ae3d4; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: wait; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.join { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.join input { text-transform: uppercase; letter-spacing: 0.15em; }

#guide { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.keys dt { color: var(--text); font-weight: 600; }
.keys dd { margin: 0; }
.items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 0; padding: 0; list-style: none; }
.items li { display: flex; align-items: center; gap: 8px; }
.items canvas { position: static; width: 26px; height: 26px; flex: none; cursor: default; }

.code { font-size: 54px; line-height: 1.1; letter-spacing: 0.16em; font-variant-numeric: tabular-nums; }
.slots { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.slots li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--bg); border-radius: 8px; }
.slots .s0 { border-left: 4px solid var(--p0); }
.slots .s1 { border-left: 4px solid var(--p1); }
.slots small { color: var(--muted); font-size: 14px; }

.final { font-size: 58px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }

.hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  pointer-events: none;
  z-index: 3;
}
.scorebox { text-align: center; text-shadow: 0 1px 6px #000; }
.score { font-size: clamp(26px, 5vw, 42px); font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.meta { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.card { width: min(240px, 100%); padding: 7px 10px; background: rgba(13, 20, 32, 0.82); border-radius: 8px; font-size: 14px; }
.card:empty { visibility: hidden; }
.card.p1 { justify-self: end; }
.card .who { display: flex; justify-content: space-between; gap: 8px; }
.card .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.p0 b { color: var(--p0); }
.card.p1 b { color: var(--p1); }
.bar { height: 7px; margin: 4px 0; background: #293648; border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.card.p0 .bar i { background: var(--p0); }
.card.p1 .bar i { background: var(--p1); }
.pow { color: var(--muted); font-size: 12px; min-height: 18px; font-variant-numeric: tabular-nums; }

.banner {
  position: fixed;
  top: 22%;
  left: 16px;
  right: 16px;
  text-align: center;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 700;
  color: var(--danger);
  text-shadow: 0 2px 10px #000;
  pointer-events: none;
  z-index: 3;
}
.count {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 120px;
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 4px 24px #000;
  z-index: 4;
}
.mute {
  position: fixed;
  right: 8px;
  bottom: 8px;
  min-height: 32px;
  padding: 4px 10px;
  color: var(--muted);
  font: 13px var(--font);
  background: rgba(13, 20, 32, 0.8);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  z-index: 6;
}

.touch { position: fixed; inset: 0; z-index: 2; touch-action: none; }
.stick { position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border: 2px solid rgba(232, 238, 245, 0.28); border-radius: 50%; pointer-events: none; }
.stick i { position: absolute; left: 35px; top: 35px; width: 40px; height: 40px; background: rgba(232, 238, 245, 0.35); border-radius: 50%; }
.dashbtn {
  position: absolute;
  right: 22px;
  bottom: 48px;
  width: 68px;
  height: 68px;
  color: var(--text);
  font: 600 15px var(--font);
  background: rgba(70, 214, 196, 0.22);
  border: 2px solid var(--p0);
  border-radius: 50%;
  touch-action: none;
}

.rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate.show {
    display: block;
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 12px;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    pointer-events: none;
    z-index: 3;
  }
}

@media (max-width: 560px) {
  .panel { padding: 20px; }
  .modes { grid-template-columns: 1fr; }
  .meta { font-size: 12px; }
  .card { padding: 5px 7px; font-size: 12px; }
  .code { font-size: 44px; }
}
