:root {
  --ink: #fff;
  --glass: rgba(28, 26, 34, .48);
  --glass-line: rgba(255, 255, 255, .2);
  --accent: #ffd86b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1d1633;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  touch-action: none;
}

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
}

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.tl, .tr { display: flex; gap: 8px; align-items: center; }
.tr { flex-wrap: wrap; justify-content: flex-end; }

.pill {
  color: var(--ink);
  font: 600 14px/1 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  padding: 11px 16px;
  border-radius: 999px;
  white-space: nowrap;
}
button.pill { cursor: pointer; }
button.pill:active { transform: scale(.97); }
.pill.round { width: 40px; height: 40px; padding: 0; font-size: 18px; display: grid; place-items: center; }
.countdown { font-variant-numeric: tabular-nums; }
.countdown.live { background: rgba(255, 130, 170, .55); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

/* ---------- server panel ---------- */
.panel {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 52px);
  left: 10px;
  width: min(320px, calc(100% - 20px));
  max-height: 60dvh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(28, 26, 34, .8);
}
.panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-size: 15px; }
.panel-head .x { background: none; border: 0; color: var(--ink); font-size: 16px; cursor: pointer; }
.srv-list { overflow-y: auto; padding: 0 10px 10px; display: grid; gap: 6px; }
.srv {
  color: var(--ink);
  font: inherit;
  text-align: left;
  background: rgba(255, 255, 255, .1);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 12px;
  display: grid;
  gap: 6px;
  cursor: pointer;
}
.srv.cur { border-color: var(--accent); background: rgba(255, 216, 107, .16); }
.srv:disabled { opacity: .4; cursor: not-allowed; }
.srv .row { display: flex; justify-content: space-between; font-size: 14px; }
.srv .bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.srv .bar i { display: block; height: 100%; background: #7bc4ff; }
.srv.hot .bar i { background: #ff8fab; }

/* ---------- bottom action bar ---------- */
.actions {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 26px;
  max-width: calc(100% - 20px);
}
.act {
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 18px;
  padding: 8px 12px;
  min-width: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.act .ico { font-size: 26px; line-height: 1; }
.act .lbl { font-size: 12px; line-height: 1.2; text-align: center; word-break: keep-all; }
.act:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.act.on { background: rgba(255, 216, 107, .28); }
.act.cool, .act:active:not(:disabled) { transform: scale(.92); background: rgba(255, 255, 255, .22); }
.act:disabled { opacity: .45; cursor: default; }

/* ---------- joystick ---------- */
.joy {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 96px);
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  border: 2px solid rgba(255, 255, 255, .3);
  display: none;
  place-items: center;
  touch-action: none;
}
.knob { width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, .55); pointer-events: none; }
@media (pointer: coarse) { .joy { display: grid; } }

/* ---------- small messages ---------- */
.hint, .toast, .help {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.hint { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 92px); background: var(--accent); color: #2b2417; font-weight: 600; animation: blink 1.4s steps(2) infinite; }
.hint[hidden], .toast[hidden] { display: none; }
@keyframes blink { 50% { opacity: .6; } }
.toast { top: calc(max(10px, env(safe-area-inset-top)) + 56px); background: #ff8fab; color: #2b1320; font-weight: 600; }
.help { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 150px); background: rgba(0, 0, 0, .35); color: #fff; transition: opacity 1s; }
.help.gone { opacity: 0; }
.status { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 16, 36, .7); font-size: 18px; text-align: center; padding: 20px; }
.status[hidden] { display: none; }

/* ---------- loading ---------- */
#loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: #1d1633; z-index: 10; transition: opacity .5s; font-size: 16px; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (pointer: coarse) { .help { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 250px); } }

/* ---------- small screens ---------- */
@media (max-width: 560px) {
  .pill { padding: 10px 12px; font-size: 13px; }
  .topbar { flex-wrap: wrap; }
  .tl { flex: 1 1 100%; }
  .tr { flex: 1 1 100%; gap: 6px; justify-content: space-between; flex-wrap: nowrap; }
  .countdown { flex: 1; text-align: left; }
  .panel { top: calc(max(10px, env(safe-area-inset-top)) + 104px); }
  .toast { top: calc(max(10px, env(safe-area-inset-top)) + 108px); }
  .act { min-width: 0; flex: 1; padding: 8px 6px; }
  .act .lbl { font-size: 11px; }
  .actions { left: 10px; right: 10px; transform: none; justify-content: space-between; }
  .joy { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 100px); width: 110px; height: 110px; }
}
