:root {
  --bg: #080b12;
  --panel: rgba(17, 24, 39, 0.82);
  --line: rgba(255,255,255,0.13);
  --text: #f8fafc;
  --muted: #a7b0c2;
  --tile: #151a24;
  --tile-line: rgba(255,255,255,0.08);
  --selected: #00ffff;
  --grid-cols: 10;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body {
  height: 100svh;
  min-height: 100svh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 0, 255, .20), transparent 30%),
    radial-gradient(circle at 90% 10%, rgba(0, 255, 255, .17), transparent 28%),
    var(--bg);
  overflow-x: hidden;
}

.opening {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255,214,64,.23), transparent 28%),
    radial-gradient(circle at 50% 52%, rgba(255,102,0,.16), transparent 44%),
    rgba(3, 6, 18, .96);
  transition: opacity .42s ease, transform .42s ease, visibility .42s ease;
}
.opening.hide {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.04);
  pointer-events: none;
}
.sun-globe {
  position: relative;
  width: min(56vw, 250px);
  aspect-ratio: 1;
  border-radius: 50%;
  transform-style: preserve-3d;
  animation: globeFloat 2.4s ease-in-out infinite;
  filter: drop-shadow(0 0 22px rgba(255, 196, 0, .85)) drop-shadow(0 0 70px rgba(255, 72, 0, .55));
}
.globe-core,
.globe-grid,
.globe-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
.globe-core {
  background:
    radial-gradient(circle at 32% 24%, #fff9b8 0 8%, #ffe66d 13%, transparent 22%),
    radial-gradient(circle at 36% 32%, #fff06a 0 16%, #ffb000 42%, #ff5a00 72%, #b31800 100%);
  box-shadow:
    inset -24px -18px 44px rgba(90, 0, 0, .42),
    inset 18px 10px 32px rgba(255,255,255,.25),
    0 0 0 1px rgba(255,255,255,.2),
    0 0 70px rgba(255, 123, 0, .92);
  overflow: hidden;
}
.globe-core::before {
  content: "";
  position: absolute;
  inset: -20% -45%;
  background:
    repeating-linear-gradient(92deg, transparent 0 20px, rgba(255,255,255,.22) 22px 25px, transparent 28px 44px),
    radial-gradient(ellipse at 28% 38%, rgba(255,255,255,.25), transparent 28%),
    radial-gradient(ellipse at 72% 62%, rgba(120,0,0,.22), transparent 34%);
  animation: sunBands 2.8s linear infinite;
  mix-blend-mode: screen;
}
.globe-grid {
  border: 1px solid rgba(255,255,255,.42);
  background:
    repeating-radial-gradient(ellipse at center, transparent 0 21px, rgba(255,255,255,.23) 22px 23px, transparent 24px 38px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(255,255,255,.19) 32px 33px, transparent 34px 62px);
  opacity: .42;
  mix-blend-mode: screen;
}
.globe-grid-a { animation: globeSpin 3.2s linear infinite; }
.globe-grid-b { transform: rotate(90deg) rotateX(62deg); animation: globeSpinReverse 4.4s linear infinite; opacity: .28; }
.globe-ring {
  inset: 7%;
  border: 2px solid rgba(255, 247, 179, .6);
  transform: rotateX(66deg) rotateZ(-18deg);
  box-shadow: 0 0 18px rgba(255,220,80,.55), inset 0 0 18px rgba(255,220,80,.35);
}
.opening-title {
  font-size: clamp(24px, 8vw, 46px);
  font-weight: 1000;
  letter-spacing: -.07em;
  text-shadow: 0 0 26px rgba(255, 184, 0, .72), 0 0 44px rgba(255, 55, 0, .45);
}
@keyframes globeSpin { to { transform: rotateY(360deg) rotateZ(360deg); } }
@keyframes globeSpinReverse { to { transform: rotate(90deg) rotateX(62deg) rotateZ(-360deg); } }
@keyframes globeFloat { 0%,100% { transform: translateY(0) rotateX(-8deg); } 50% { transform: translateY(-8px) rotateX(8deg); } }
@keyframes sunBands { to { transform: translateX(18%); } }

.app {
  width: min(100%, 460px);
  height: 100svh;
  min-height: 0;
  margin: 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) 8px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 7px;
  overflow: hidden;
  touch-action: none;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(0,0,0,.26);
  backdrop-filter: blur(14px);
}

.selected-button,
.ghost,
.status-pill {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  color: var(--text);
  font: inherit;
}

.selected-button {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  cursor: pointer;
  font-weight: 900;
}
.selected-preview {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: var(--selected);
  box-shadow: 0 0 20px var(--selected);
  border: 2px solid rgba(255,255,255,.72);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
}
.selected-preview.has-icon { text-shadow: 0 1px 3px rgba(0,0,0,.45); }
#selectedName {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #ff0066;
  box-shadow: 0 0 0 4px rgba(255,0,102,.13);
  flex: 0 0 auto;
}
.status-dot.ok { background: #00ff00; box-shadow: 0 0 0 4px rgba(0,255,0,.13), 0 0 16px #00ff00; }
#statusText { display: none; }
.ghost { padding: 5px 8px; font-size: 12px; font-weight: 900; cursor: pointer; white-space: nowrap; }
.selected-button:active, .ghost:active { transform: scale(.96); }
.selected-button:disabled { opacity: .62; cursor: not-allowed; }

.game-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 82px;
  grid-template-areas:
    "start timer result"
    "host host host"
    "rank rank rank";
  gap: 6px;
  padding: 6px;
  background: rgba(17, 24, 39, .74);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(0,0,0,.23);
  backdrop-filter: blur(14px);
}
.game-button,
.timer-card,
.round-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
}
.game-button {
  grid-area: start;
  padding: 8px 10px;
  background: linear-gradient(135deg, #ff0066, #ff9900 55%, #ffff00);
  color: #120617;
  font: inherit;
  font-size: 14px;
  font-weight: 1000;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255,0,102,.28);
}
.game-button:disabled {
  opacity: .72;
  color: #fff;
  background: rgba(255,255,255,.10);
  box-shadow: none;
}
.round-button {
  grid-area: result;
  padding: 7px 8px;
  background: rgba(255,255,255,.09);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 1000;
  cursor: pointer;
  white-space: nowrap;
}
.round-button:active, .admin-button:active, .admin-submit:active { transform: scale(.96); }
.host-row {
  grid-area: host;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 13px;
  background: rgba(255,255,255,.055);
}
.host-row span {
  min-width: 0;
  color: #fff2a8;
  font-size: 12px;
  font-weight: 1000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.host-row span.me { color: #b7ffdb; text-shadow: 0 0 14px rgba(0,255,128,.34); }
.admin-button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.09);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 1000;
  cursor: pointer;
}
.timer-card {
  grid-area: timer;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(255,255,255,.07);
}
.timer-card span { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: -.02em; }
.timer-card strong { font-size: 20px; line-height: 1; font-weight: 1000; font-variant-numeric: tabular-nums; }
.ranking {
  grid-area: rank;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.ranking li {
  min-width: 0;
  position: relative;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px;
  padding: 5px 5px 5px 7px;
  border: 1px solid rgba(255,255,255,.10);
  border-left-width: 3px;
  border-radius: 11px;
  background: rgba(255,255,255,.052);
  font-size: 10px;
  color: var(--muted);
}
.ranking li.manageable { grid-template-columns: auto auto minmax(0, 1fr) auto auto; }
.ranking li.online { border-color: rgba(89, 255, 172, .18); border-left-color: #35ff9f; box-shadow: inset 2px 0 0 rgba(53,255,159,.18); }
.ranking li.offline { opacity: .50; filter: grayscale(.30); border-color: rgba(148, 163, 184, .12); border-left-color: #64748b; }
.ranking li.waiting { opacity: .68; border-color: rgba(255, 214, 64, .16); border-left-color: #ffd640; }
.ranking li.manageable { cursor: pointer; }
.ranking li.manageable::after {
  content: "⋯";
  justify-self: end;
  color: rgba(255,255,255,.66);
  font-size: 13px;
  font-weight: 1000;
  line-height: 1;
}
.ranking li.manageable:active { transform: scale(.98); }
.ranking li.me { border-color: rgba(255,255,255,.36); background: rgba(255,255,255,.12); color: #fff; }
.ranking li.me.online { border-left-color: #35ff9f; }
.ranking li.me.offline { border-left-color: #64748b; }
.ranking li.me.waiting { border-left-color: #ffd640; }
.ranking .rank-no { font-weight: 1000; color: #fff; }
.ranking i {
  width: 17px;
  height: 17px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--rank-color);
  box-shadow: 0 0 8px var(--rank-color);
  font-style: normal;
  font-size: 10px;
  line-height: 1;
}
.ranking b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking strong {
  color: #fff;
  font-variant-numeric: tabular-nums;
  display: grid;
  justify-items: end;
  line-height: 1;
  font-size: 11px;
}
.ranking strong small { color: var(--muted); font-size: 7px; font-weight: 900; }
.empty-rank { grid-column: 1 / -1 !important; display: block !important; text-align: center; }
.battle-mode .floor-wrap { border-color: rgba(255, 230, 80, .42); box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 0 34px rgba(255, 153, 0, .16), 0 18px 60px rgba(0,0,0,.38); }

.floor-wrap {
  width: 100%;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.045);
  border-radius: 20px;
  padding: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 18px 60px rgba(0,0,0,.38);
  overflow: hidden;
  touch-action: none;
}
.floor {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows, 16), minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  height: 100%;
  max-width: 100%;
  min-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tile {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  aspect-ratio: auto;
  border: 1px solid var(--tile-line);
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(255,255,255,.07), transparent), var(--tile);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 4px 10px rgba(0,0,0,.22);
  cursor: pointer;
  transition: transform .09s ease, background .16s ease, box-shadow .16s ease;
}
.tile:active, .tile.pulse { transform: translateY(2px) scale(.93); }
.tile.painted { box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 0 16px var(--c), 0 6px 15px rgba(0,0,0,.28); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,.76);
  backdrop-filter: blur(16px);
  overflow: hidden;
  touch-action: none;
}
.modal.hide { display: none; }
.modal-panel {
  width: min(360px, calc(100vw - 20px));
  max-height: calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  background: rgba(10,14,24,.95);
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 30px 100px rgba(0,0,0,.55);
  overflow: hidden;
  touch-action: none;
}
.modal-panel h1 { margin: 0 0 3px; font-size: 21px; letter-spacing: -0.05em; }
.modal-copy { margin: 0 0 10px; color: var(--muted); font-size: 12px; font-weight: 800; }
.family-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; margin-bottom: 10px; }
.family-choice {
  width: 100%;
  aspect-ratio: 1.08;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 15px;
  background: rgba(255,255,255,.07);
  color: var(--text);
  font-size: 24px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09);
  touch-action: none;
  transition: transform .08s ease, border-color .08s ease, background .08s ease;
}
.family-choice.active {
  border-color: rgba(255,255,255,.78);
  background: rgba(255,255,255,.18);
  box-shadow: 0 0 18px rgba(255,255,255,.18), inset 0 1px 0 rgba(255,255,255,.18);
}
.family-choice.taken {
  filter: grayscale(.35) brightness(.58);
  opacity: .50;
  cursor: not-allowed;
  position: relative;
}
.family-choice.taken::after {
  content: "✓";
  position: absolute;
  right: 6px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 12px;
  font-weight: 1000;
}
.family-choice:disabled { pointer-events: none; }
.family-choice:active { transform: scale(.90); }
.palette { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
.color-choice {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.72);
  cursor: pointer;
  box-shadow: 0 0 18px var(--color);
  transition: transform .08s ease, filter .08s ease, border-color .08s ease;
  touch-action: none;
}
.color-choice.active { border-color: #fff; outline: 3px solid rgba(255,255,255,.30); }
.color-choice.taken {
  filter: grayscale(.45) brightness(.55);
  opacity: .46;
  cursor: not-allowed;
  box-shadow: none;
  position: relative;
}
.color-choice.taken::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 18px;
  font-weight: 1000;
  text-shadow: 0 1px 4px rgba(0,0,0,.75);
}
.color-choice:active { transform: scale(.88); filter: brightness(1.14); }
.color-choice.taken:active { transform: none; filter: grayscale(.45) brightness(.55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.modal-head h1 { margin: 0; }
.modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}
.result-panel { max-height: calc(100svh - 24px); }
.admin-panel { display: grid; gap: 9px; }
.admin-key-label { color: var(--muted); font-size: 12px; font-weight: 1000; }
.admin-key-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 1000;
  text-align: center;
  outline: none;
}
.admin-key-input:focus { border-color: rgba(255,242,168,.72); box-shadow: 0 0 18px rgba(255,214,64,.18); }
.admin-submit {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 14px;
  background: linear-gradient(135deg, #fff2a8, #ff9900);
  color: #1a1002;
  font: inherit;
  font-weight: 1000;
  cursor: pointer;
}
.player-admin-panel { display: grid; gap: 10px; }
.player-admin-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-areas: "icon name" "icon meta";
  align-items: center;
  gap: 2px 9px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.13);
  border-left: 4px solid var(--rank-color, #35ff9f);
  border-radius: 16px;
  background: rgba(255,255,255,.06);
}
.player-admin-card i {
  grid-area: icon;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--rank-color, #fff);
  box-shadow: 0 0 12px var(--rank-color, rgba(255,255,255,.5));
  font-style: normal;
  font-size: 18px;
}
.player-admin-card b { grid-area: name; min-width: 0; color: #fff; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-admin-card span { grid-area: meta; color: var(--muted); font-size: 12px; font-weight: 900; }
.danger-submit {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: linear-gradient(135deg, #ff4d6d, #b91c1c);
  color: #fff;
  font: inherit;
  font-weight: 1000;
  cursor: pointer;
}
.danger-submit:active { transform: scale(.97); }
.round-history { display: grid; gap: 8px; max-height: min(68svh, 560px); overflow: hidden; }
.empty-results { margin: 0; color: var(--muted); text-align: center; font-weight: 900; padding: 18px 0; }
.round-card {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  background: rgba(255,255,255,.055);
  padding: 9px;
}
.round-card header { display: grid; gap: 2px; margin-bottom: 6px; }
.round-card header b { font-size: 13px; }
.round-card header span { color: #fff2a8; font-size: 12px; font-weight: 1000; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-card ol { display: grid; gap: 4px; list-style: none; padding: 0; margin: 0; }
.round-card li {
  display: grid;
  grid-template-columns: 18px 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,.055);
  font-size: 11px;
}
.round-card li span { font-weight: 1000; color: #fff; }
.round-card li i { width: 18px; height: 18px; border-radius: 999px; display: grid; place-items: center; background: var(--rank-color); font-style: normal; font-size: 11px; }
.round-card li b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-card li strong { display: grid; justify-items: end; color: #fff; font-size: 12px; line-height: 1.02; }
.round-card li small { color: var(--muted); font-size: 8px; }
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  background: radial-gradient(circle at 50% 42%, rgba(255,214,64,.18), transparent 31%), rgba(3, 6, 18, .50);
  backdrop-filter: blur(5px);
  pointer-events: none;
  touch-action: none;
}
.countdown-overlay.hide { display: none; }
.countdown-overlay span { font-size: 18px; font-weight: 1000; color: #fff2a8; text-shadow: 0 0 18px rgba(255,214,64,.7); }
.countdown-overlay strong {
  font-size: clamp(92px, 30vw, 150px);
  line-height: .9;
  font-weight: 1000;
  color: #fff;
  text-shadow: 0 0 24px rgba(255,255,255,.55), 0 0 58px rgba(255,145,0,.72);
  animation: countdownPop 1s ease-in-out infinite;
}
@keyframes countdownPop { 0% { transform: scale(.78); opacity: .35; } 18% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(.94); opacity: .7; } }
.toast { position: fixed; left: 50%; bottom: 14px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 13px; border-radius: 999px; background: rgba(15,23,42,.92); border: 1px solid var(--line); color: var(--text); transition: .22s ease; z-index: 12; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .app { padding: 12px; }
  .toolbar { border-radius: 20px; }
  .floor-wrap { padding: 8px; border-radius: 24px; }
  .floor { gap: 5px; }
  .tile { border-radius: 11px; }
}
