:root {
  --night: #1B0F2E;
  --plum: #2C1747;
  --plum-2: #3A2160;
  --teal: #16303A;
  --cyan: #5CF2FF;
  --gold: #FFE14D;
  --orange: #FF9F1C;
  --rage: #FF4F8B;
  --paper: #F3ECFF;
  --muted: #B3A6CC;
  --ink: #140A22;
  --line: rgba(243, 236, 255, 0.12);
  --display: Bungee, "Black Han Sans", Impact, system-ui, sans-serif;
  --body: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: 16px;
  --dock-h: 84px;
  color-scheme: dark;
}
:lang(ko) { --display: Bungee, "Black Han Sans", Impact, system-ui, sans-serif; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--paper);
  font: 400 15px/1.55 var(--body);
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gutter);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; min-width: 0; }
.brand-name { font: 400 20px/1 var(--display); letter-spacing: 0.01em; color: var(--gold); text-shadow: 3px 3px 0 var(--rage); }
.brand-tag { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  background: var(--plum); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.chip:hover { background: var(--plum-2); }
.chip-coffee { background: #3B2A12; border-color: rgba(255, 225, 77, 0.35); color: var(--gold); }
.chip-me { background: transparent; border-style: dashed; }
.chip .ico { font-size: 14px; line-height: 1; }
.brand-name { white-space: nowrap; }
.top-actions { flex-wrap: nowrap; }
.chip-me { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 22px; }
@media (max-width: 599px) {
  .top { gap: 8px; }
  .brand-tag { display: none; }
  .brand-name { font-size: 15px; text-shadow: 2px 2px 0 var(--rage); }
  #sound-label, .chip-coffee span:not(.ico) { display: none; }
  .chip { padding: 6px 9px; min-height: 34px; font-size: 12px; }
  .chip-me { max-width: 84px; }
}

/* ---------- ticker ---------- */
.ticker {
  margin: 0 var(--gutter);
  padding: 7px 12px;
  border-left: 4px solid var(--rage);
  background: linear-gradient(90deg, rgba(255, 79, 139, 0.16), transparent 80%);
  font-weight: 600; font-size: 14px;
  min-height: 36px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#ticker-text { transition: opacity 0.3s; }
#ticker-text.swap { opacity: 0; }

/* ---------- layout ---------- */
.layout { display: flex; flex-direction: column; gap: 12px; padding: 12px var(--gutter) 0; }
@media (min-width: 1024px) {
  .layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
  .stage { position: sticky; top: 8px; }
}

/* ---------- boss frame ---------- */
.stage { display: flex; flex-direction: column; gap: 10px; }
.bossframe { display: grid; gap: 6px; }
.boss-id { display: flex; align-items: center; gap: 10px; }
.boss-num {
  flex: none; display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--gold);
  font: 400 14px/1 var(--display); color: var(--gold);
}
.boss-name { margin: 0; font: 400 clamp(20px, 5vw, 30px)/1.05 var(--display); letter-spacing: 0.02em; }
.boss-title { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.hp {
  position: relative; height: 28px;
  background: var(--ink); border: 2px solid #000; border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.hp-lag, .hp-fill { position: absolute; inset: 0 auto 0 0; width: 100%; }
.hp-lag { background: #FFF3F7; transition: width 0.9s ease-in 0.25s; z-index: 1; }
.hp-fill {
  z-index: 2;
  background: linear-gradient(180deg, #FF6F8F 0%, #E0245E 55%, #A3123F 100%);
  transition: width 0.15s linear;
}
.hp-text {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center;
  font: 400 13px/1 var(--display); letter-spacing: 0.03em;
  text-shadow: 0 1px 0 #000, 0 0 4px #000;
  font-variant-numeric: tabular-nums;
}
.boss-hits { margin: 0; font-size: 12px; color: var(--muted); }

/* ---------- arena ---------- */
.arena-wrap {
  position: relative;
  height: clamp(340px, 54vh, 620px);
  border-radius: 14px;
  overflow: hidden;
  background: var(--plum);
  box-shadow: 0 0 0 2px #000, 0 0 0 4px rgba(92, 242, 255, 0.16);
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 1024px) { .arena-wrap { height: calc(100dvh - 370px); min-height: 420px; } }
#arena { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

.bubble {
  position: absolute; z-index: 2;
  max-width: min(300px, 62%);
  padding: 10px 14px;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 16px;
  font-weight: 700; font-size: 14px; line-height: 1.4;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  transform-origin: 0 100%;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.bubble::after {
  content: ""; position: absolute; left: 18px; bottom: -14px;
  border: 12px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
.bubble.hide { opacity: 0; transform: scale(0.85); }
.bubble.flip { transform-origin: 100% 100%; }
.bubble.flip::after { left: auto; right: 18px; }
.bubble .caret { display: inline-block; width: 0.5em; animation: blink 0.8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- dock & attack button ---------- */
.dock {
  display: flex; gap: 12px; align-items: stretch;
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 calc(var(--gutter) * -1);
  padding: 10px var(--gutter) max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(27, 15, 46, 0.6), var(--night) 35%);
  backdrop-filter: blur(6px);
}
@media (min-width: 1024px) {
  /* Desktop: the attack button sits centred under the boss, big enough to be the obvious thing to press */
  .dock { position: static; margin: 0; padding: 0; background: none; backdrop-filter: none; flex-direction: column; align-items: center; gap: 8px; }
  .dock-side { flex: none; flex-direction: row; align-items: baseline; justify-content: center; gap: 14px; min-height: 26px; }
}
.attack {
  position: relative; flex: 1 1 60%;
  display: grid; justify-items: start; align-content: center; gap: 2px;
  min-height: 72px; padding: 10px 18px 16px;
  border: 3px solid #000; border-radius: 14px;
  background: var(--gold); color: var(--ink);
  box-shadow: 0 6px 0 #B8860B, 0 6px 0 2px #000;
  text-align: left;
  overflow: hidden;
  transition: transform 0.05s, box-shadow 0.05s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.attack:active, .attack.pressed { transform: translateY(5px); box-shadow: 0 1px 0 #B8860B, 0 1px 0 2px #000; }
.attack-main { font: 400 clamp(18px, 4.6vw, 24px)/1.05 var(--display); }
.attack-sub { font-size: 13px; font-weight: 700; opacity: 0.8; font-variant-numeric: tabular-nums; }
.pips { position: absolute; left: 10px; right: 10px; bottom: 6px; display: flex; gap: 2px; }
.pips i { flex: 1; height: 5px; border-radius: 2px; background: rgba(20, 10, 34, 0.75); }
.pips i.used { background: rgba(20, 10, 34, 0.15); }
.recharge { position: absolute; left: 0; bottom: 0; height: 100%; background: rgba(92, 242, 255, 0.18); width: 0; pointer-events: none; }
.attack[data-state="active"] { background: var(--rage); color: #fff; box-shadow: 0 6px 0 #8E1E48, 0 6px 0 2px #000; }
.attack[data-state="active"] .pips i { background: #fff; }
.attack[data-state="active"] .pips i.used { background: rgba(255, 255, 255, 0.2); }
.attack[data-state="active"][data-tier="furious"] { background: var(--orange); color: var(--ink); }
.attack[data-state="active"][data-tier="berserk"] { background: #FF2E63; color: #fff; animation: throb 0.35s ease-in-out infinite alternate; }
@keyframes throb { to { filter: brightness(1.15) saturate(1.2); } }
.attack[data-state="recharging"], .attack[data-state="intermission"] {
  background: var(--plum-2); color: var(--paper); cursor: default;
  box-shadow: 0 6px 0 #150A26, 0 6px 0 2px #000;
}
.attack[data-state="recharging"] .pips, .attack[data-state="intermission"] .pips { display: none; }
.attack[data-state="join"] { background: var(--cyan); box-shadow: 0 6px 0 #1F8F99, 0 6px 0 2px #000; }
.attack[data-state="join"] .pips { display: none; }

.dock-side { flex: 1 1 40%; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; }
.rage { margin: 0; font: 400 clamp(16px, 4vw, 22px)/1.1 var(--display); color: var(--gold); min-height: 1.1em; transition: transform 0.12s; }
.rage.bump { transform: scale(1.25); }
.rage[data-tier="furious"] { color: var(--orange); }
.rage[data-tier="berserk"] { color: var(--rage); }
.mine { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mine b { color: var(--paper); font-weight: 700; }

/* ---------- panels ---------- */
.panels { display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0; }
@media (min-width: 600px) and (max-width: 1023px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats div { padding: 10px 12px; background: var(--plum); border-radius: 10px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font: 400 20px/1.1 var(--display); font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; padding: 9px 12px; min-height: 44px;
  background: none; border: 0; border-bottom: 3px solid transparent;
  color: var(--muted); font-weight: 700; font-size: 14px;
}
.tabs button[aria-selected="true"] { color: var(--paper); border-bottom-color: var(--gold); }
.pane { min-height: 200px; }
.pane-title { margin: 4px 0 10px; font-size: 16px; font-weight: 800; }
.empty { color: var(--muted); font-size: 14px; }

.map-wrap { position: relative; }
#map { display: block; width: 100%; touch-action: pan-y; }
.map-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 10px));
  padding: 4px 8px; border-radius: 6px;
  background: var(--ink); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700; white-space: nowrap; pointer-events: none;
}
.map-legend { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.legend-bar { width: 72px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #2A1F3D, hsl(333, 67%, 29%), hsl(300, 100%, 64%)); }
.mini-board { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }

.bar-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; }
.bar-row .rk { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.bar-row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 700; }
.bar-row .bar { grid-column: 2 / 4; height: 4px; border-radius: 2px; background: var(--rage); transform-origin: left; }
.bar-row.me .nm { color: var(--gold); font-weight: 800; }
.bar-row.me .bar { background: var(--gold); }

.board { width: 100%; border-collapse: collapse; font-size: 14px; }
.board th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.board td { padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.board td:last-child, .board th:last-child, .board td:nth-child(3), .board th:nth-child(3) { text-align: right; }
.board tr.me td { color: var(--gold); font-weight: 700; }

.raiders, .log, .fallen { list-style: none; margin: 0; padding: 0; }
.raiders li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; font-size: 13px; }
.log li { padding: 3px 0; color: var(--paper); }
.log li.crit { color: var(--orange); font-weight: 700; }
.log li.boss { color: var(--cyan); }
.log li.mine { color: var(--gold); }
.fallen li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.fallen .fb-name { font: 400 17px/1.2 var(--display); }
.fallen .fb-meta { font-size: 13px; color: var(--muted); }

/* ---------- footer ---------- */
.foot { padding: 20px var(--gutter) calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); margin-top: 12px; }
.foot p { margin: 0 0 4px; }

/* ---------- dialogs ---------- */
.modal {
  width: min(440px, calc(100vw - 2 * var(--gutter)));
  padding: 22px;
  background: var(--plum); color: var(--paper);
  border: 3px solid #000; border-radius: 16px;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
}
.modal::backdrop { background: rgba(10, 4, 20, 0.72); }
.modal h2 { margin: 0 0 8px; font: 400 22px/1.15 var(--display); }
.modal-body { margin: 0 0 12px; color: var(--paper); }
.muted { color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 12px; font-weight: 700; font-size: 14px; }
.field input, .field select {
  min-height: 48px; padding: 10px 12px;
  background: var(--ink); border: 2px solid var(--plum-2); border-radius: 10px;
  font-size: 16px; font-weight: 600;
}
.field input:focus, .field select:focus { border-color: var(--cyan); outline: none; }
.field small { color: var(--muted); font-weight: 500; }
.form-error { min-height: 1.2em; margin: 0 0 8px; color: #FF8FAE; font-weight: 700; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; font-weight: 800; text-decoration: none;
}
.btn-primary { background: var(--gold); color: var(--ink); border: 3px solid #000; box-shadow: 0 4px 0 #000; }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.btn-ghost { background: transparent; color: var(--paper); border: 2px solid var(--line); }
.summary-dmg { margin: 4px 0 8px; font: 400 44px/1 var(--display); color: var(--gold); text-shadow: 3px 3px 0 var(--rage); font-variant-numeric: tabular-nums; }
.summary-calm { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

/* ---------- victory ---------- */
.victory {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-content: center; text-align: center; gap: 6px;
  padding: var(--gutter);
  background: radial-gradient(circle at center, rgba(27, 15, 46, 0.55), rgba(27, 15, 46, 0.88));
  pointer-events: none;
  animation: victory-in 0.5s ease-out;
}
.victory p { margin: 0; font-weight: 700; font-size: 16px; }
.victory-title { font: 400 clamp(32px, 9vw, 72px)/1 var(--display) !important; color: var(--gold); text-shadow: 4px 4px 0 var(--rage), 0 0 30px rgba(255, 225, 77, 0.5); margin-bottom: 10px !important; }
.victory-next { margin-top: 14px !important; color: var(--cyan); }
@keyframes victory-in { from { opacity: 0; transform: scale(1.2); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 24px); transform: translateX(-50%); z-index: 30;
  padding: 10px 16px; border-radius: 10px;
  background: var(--ink); border: 2px solid var(--cyan);
  font-weight: 700; font-size: 14px; max-width: calc(100vw - 32px);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 599px) {
  .attack { flex-basis: 66%; padding: 10px 14px 16px; }
  .dock-side { flex-basis: 34%; }
  .mine { font-size: 11px; }
}

/* Desktop attack button: declared after the base .attack rules so it wins */
@media (min-width: 1024px) {
  .attack { flex: none; width: min(520px, 100%); min-height: 84px; justify-items: center; text-align: center; }
  .attack-main { font-size: 28px; }
}

/* ---------- pixel-art battle area ---------- */
.arena-wrap { border-radius: 0; box-shadow: 0 0 0 3px #000, 0 0 0 6px #3A2160, 6px 6px 0 6px rgba(0, 0, 0, 0.45); }
#arena { image-rendering: pixelated; }
.bubble {
  font-family: Galmuri11, var(--body);
  font-weight: 400; font-size: 13px; line-height: 1.5;
  border-radius: 0; border-width: 3px;
  box-shadow: 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 6px 6px 0 rgba(0, 0, 0, 0.45);
  border-color: var(--paper);
  transition: opacity 0.12s steps(2), transform 0.12s steps(2);
}
.bubble::after { bottom: -15px; border-width: 12px 12px 0 0; border-color: var(--ink) transparent transparent transparent; }
.bubble.flip::after { border-width: 12px 0 0 12px; }
.chip { white-space: nowrap; flex: none; }
@media (max-width: 420px) { .chip-me { max-width: 72px; } .brand-name { font-size: 14px; } }

/* =========================================================================
   Layout v2: map & rankings on the left, battle in the centre, stats & fallen bosses on the right.
   The page stops growing past --page-max so it doesn't stretch on very wide screens.
   ========================================================================= */
:root { --page-max: 1680px; }
.top, .layout, .foot { width: 100%; max-width: var(--page-max); margin-inline: auto; }
.ticker { max-width: calc(var(--page-max) - 2 * var(--gutter)); margin: 0 auto; width: calc(100% - 2 * var(--gutter)); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.layout { display: flex; flex-direction: column; gap: 14px; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { padding: 12px 14px; background: var(--plum); border-radius: 10px; min-width: 0; }
.card-title { margin: 0 0 10px; font-size: 15px; font-weight: 800; }
.card .empty { margin: 6px 0 0; }
.scroll { max-height: 340px; overflow-y: auto; scrollbar-width: thin; }
.stats { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 700px) and (max-width: 1199px) {
  .layout { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .stage { grid-column: 1 / -1; position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1200px) {
  .layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 280px; grid-template-areas: "left center right"; gap: 18px; align-items: start; }
  .stage { grid-area: center; position: sticky; top: 8px; }
  .side-left { grid-area: left; }
  .side-right { grid-area: right; }
}

/* ---------- combat log inside the battle window (last 5 lines) ---------- */
.combat-log {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  margin: 0; padding: 18px 10px 8px;
  list-style: none;
  display: flex; flex-direction: column; gap: 1px;
  background: linear-gradient(180deg, transparent, rgba(12, 6, 22, 0.78) 45%);
  font: 400 11px/1.45 Galmuri11, var(--body);
  pointer-events: none;
}
.combat-log:empty { display: none; }
.combat-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #E9E1FA; text-shadow: 1px 1px 0 #000; }
.combat-log li:nth-last-child(5) { opacity: 0.45; }
.combat-log li:nth-last-child(4) { opacity: 0.65; }
.combat-log li:nth-last-child(3) { opacity: 0.85; }
.combat-log li.crit { color: var(--orange); }
.combat-log li.boss { color: var(--cyan); }
.combat-log li.mine { color: var(--gold); }

/* ---------- scrolling ticker ---------- */
.ticker { position: relative; overflow: hidden; padding: 0; display: flex; align-items: center; }
.ticker-track { display: flex; align-items: center; gap: 0; white-space: nowrap; will-change: transform; padding: 7px 0; }
.tk { display: inline-flex; align-items: center; gap: 8px; padding-right: 36px; font-weight: 600; font-size: 14px; }
.tk::before { content: "◆"; color: var(--rage); font-size: 10px; }
.tk.fallen { color: var(--gold); }
.tk.arrived { color: var(--cyan); }
.tk.event::before { content: "!"; color: var(--gold); font-weight: 900; }
.ticker-track { flex: none; }
.board .pct { color: var(--muted); font-size: 11px; margin-left: 4px; }

/* ---------- world map readability ---------- */
.map-wrap { border-radius: 8px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(243, 236, 255, 0.08); }
.map-legend { margin: 8px 0 4px; font-size: 12px; color: var(--muted); }
.map-scale { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--paper); font-variant-numeric: tabular-nums; }
.map-scale li { display: inline-flex; align-items: center; gap: 4px; }
.map-scale .sw { width: 12px; height: 12px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3); }
@media (min-width: 1200px) { .layout { grid-template-columns: 340px minmax(0, 1fr) 280px; } }

/* ---------- desktop dock: rage label | attack button | my damage, all on one row ---------- */
@media (min-width: 1024px) {
  .dock { display: grid; grid-template-columns: minmax(0, 1fr) min(460px, 50%) minmax(0, 1fr); align-items: center; gap: 16px; }
  .dock-side { display: contents; }
  .rage { grid-column: 1; grid-row: 1; justify-self: end; text-align: right; }
  .attack { grid-column: 2; grid-row: 1; width: 100%; min-height: 76px; }
  .attack-main { font-size: 26px; }
  .mine { grid-column: 3; grid-row: 1; justify-self: start; font-size: 13px; line-height: 1.5; }
  .arena-wrap { height: clamp(360px, calc(100dvh - 400px), 620px); min-height: 0; }
}

.card-note { margin: 8px 0 0; font-size: 11px; color: var(--muted); }

/* AI service rows keep their own colours, even for your own row */
.ai-row .bar, .ai-row.me .bar { height: 6px; }
.ai-sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }

/* Coffee card in the right column */
.card-coffee { background: linear-gradient(160deg, #3B2A12, var(--plum) 70%); box-shadow: inset 0 0 0 1px rgba(255, 225, 77, 0.25); }
.card-coffee .card-title { color: var(--gold); }
.btn-coffee { width: 100%; margin-top: 10px; }

/* ---------- Change AI: top-left corner inside the battle window ---------- */
.change-ai {
  position: absolute; top: 10px; left: 10px; z-index: 3;
  display: grid; justify-items: start; gap: 2px;
  padding: 6px 10px;
  background: rgba(20, 10, 34, 0.82); color: var(--paper);
  border: 2px solid rgba(243, 236, 255, 0.25); border-radius: 0;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
  font: 400 11px/1.3 Galmuri11, var(--body);
  text-align: left;
}
.change-ai:hover { background: rgba(58, 33, 96, 0.95); border-color: var(--gold); }
.change-ai-label { font-weight: 700; color: var(--gold); }
.change-ai-now { display: inline-flex; align-items: center; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- terms page & links ---------- */
.foot a, .join-terms a { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.join-terms { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.doc-page .top a.chip { text-decoration: none; color: inherit; }
.doc { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 8px var(--gutter) 24px; }
.doc h1 { font: 400 clamp(22px, 4vw, 30px)/1.2 var(--display); margin: 12px 0 4px; }
.doc h2 { font-size: 18px; margin: 28px 0 8px; color: var(--gold); }
.doc h3 { font-size: 15px; margin: 16px 0 4px; }
.doc p, .doc li { line-height: 1.7; }
.doc ul { padding-left: 20px; margin: 4px 0; }
.doc a { color: var(--cyan); }
.doc-date { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

/* "or press Space" under the HIT button: only where there is a keyboard and mouse */
.key-hint { display: none; margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
  .key-hint { display: block; grid-column: 2; grid-row: 2; margin-top: -6px; }
}

/* ---------- no drag / no text selection on the game page ---------- */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
img, canvas, a, button { -webkit-user-drag: none; user-drag: none; }
input, select, textarea, .doc, .doc * { -webkit-user-select: text; user-select: text; }

/* ---------- second ticker line: AI news ---------- */
.ticker-news { margin-top: 6px; border-left-color: var(--cyan); background: linear-gradient(90deg, rgba(92, 242, 255, 0.1), transparent 80%); }
.ticker-tag {
  position: relative; z-index: 1; flex: none;
  margin-left: 8px; padding: 2px 6px;
  font: 400 11px/1.4 Galmuri11, var(--body); color: var(--ink); background: var(--cyan);
}
.ticker-viewport { position: relative; flex: 1; min-width: 0; overflow: hidden; margin-left: 10px; }
.tk-news { color: var(--paper); text-decoration: none; font-weight: 500; }
.tk-news:hover, .tk-news:focus-visible { color: var(--cyan); text-decoration: underline; }
.tk-news::before { color: var(--cyan); }
.tk-src { margin-left: 6px; font-size: 12px; color: var(--muted); font-weight: 400; }
.tk-src::before { content: "· "; }

/* LIVE (raid) and NEWS (AI headlines) labels: same width so the two lines line up */
.ticker-tag { min-width: 44px; text-align: center; }
.ticker-live .ticker-tag { background: var(--rage); color: #fff; }

/* The result dialog takes focus itself; no focus ring on the whole box */
#dlg-summary:focus { outline: none; }

/* ---------- round icon buttons in the header ---------- */
.icon-btn {
  flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border-radius: 50%; border: 1px solid var(--line);
  background: var(--plum); color: var(--paper);
}
.icon-btn:hover { background: var(--plum-2); }
.icon-btn.off { color: var(--muted); }
.icon-btn.off svg { opacity: 0.5; }
.icon-btn.off::after { content: ""; position: absolute; width: 22px; height: 2px; background: var(--rage); transform: rotate(-45deg); }
.icon-btn { position: relative; }

/* ---------- Stats: grid columns on wide screens, a slide-in panel below that ---------- */
.drawer-head { display: none; }
@media (min-width: 1200px) {
  .sides { display: contents; }
  .icon-stats { display: none; }
}
@media (max-width: 1199px) {
  .sides {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
    width: min(420px, 92vw);
    display: flex; flex-direction: column; gap: 12px;
    padding: 0 14px 24px;
    background: var(--night);
    box-shadow: -8px 0 0 rgba(0, 0, 0, 0.35);
    border-left: 3px solid #000;
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateX(105%);
    transition: transform 0.2s ease-out;
    visibility: hidden;
  }
  body.drawer-open .sides { transform: none; visibility: visible; }
  body.drawer-open { overflow: hidden; }
  .drawer-head {
    position: sticky; top: 0; z-index: 1;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; background: var(--night);
  }
  .drawer-title { margin: 0; font: 400 20px/1 var(--display); color: var(--gold); }
  .drawer-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(10, 4, 20, 0.6); }
  .layout { display: flex; }
}
