:root {
  --solar: #f59e0b;
  --solar-bg: #fff4d6;
  --tide: #1d7fd6;
  --tide-bg: #dcefff;
  --gale: #0f9f8f;
  --gale-bg: #d8f6ef;
  --ink: #1f2a37;
  --muted: #5b6878;
  --paper: #fffdf7;
  --line: #e7dcc4;
  --accent: #ff7a59;
  --good: #16a34a;
  --bad: #dc2626;
  --sky-1: #ffe9b8;
  --sky-2: #ffd1a1;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2) 60%, #f5d7a3);
  background-attachment: fixed;
  min-height: 100vh;
  transition: background 0.6s;
}
/* The UI grows from a beach kiosk to a tournament arena as the belts climb. */
body[data-theme="sunray"] { --sky-1: #fff1a8; --sky-2: #9fe3ff; }
body[data-theme="sunset"] { --sky-1: #ffd29d; --sky-2: #ff9e7a; }
body[data-theme="palm"] { --sky-1: #e6f7cf; --sky-2: #a9dcb0; }
body[data-theme="wave"] { --sky-1: #d6f0ff; --sky-2: #7fc3ea; }
body[data-theme="flame"] { --sky-1: #ffd0a8; --sky-2: #f0745b; }
body[data-theme="tropical"] { --sky-1: #cfe8e0; --sky-2: #7aa8a5; }
body[data-theme="driftwood"] { --sky-1: #e9dccb; --sky-2: #a99681; }
body[data-theme="solar"] { --sky-1: #fff6d8; --sky-2: #f2c45a; }
body[data-theme="encore"] { --sky-1: #3b2f63; --sky-2: #1c1838; }
body[data-theme="encore"] .muted { color: #c8c2e8; }
body[data-theme="encore"] main > section > h2, body[data-theme="encore"] main > section > h3,
body[data-theme="encore"] main > section > p { color: #fff6e0; }

main { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }
button {
  font: inherit; cursor: pointer; border: 2px solid var(--ink); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 14px; box-shadow: 0 2px 0 var(--ink); transition: transform 0.08s;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.on { background: var(--ink); color: #fff; }
button.big { background: var(--accent); color: #fff; font-weight: bold; padding: 10px 22px; }
button.small { padding: 2px 10px; font-size: 0.85em; }
small { font-weight: normal; }
.muted { color: var(--muted); }
h2 small, h3 small { color: var(--muted); font-size: 0.65em; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.seg { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.seg button { padding: 4px 10px; }

.el-solar { color: var(--solar); }
.el-tide { color: var(--tide); }
.el-gale { color: var(--gale); }

/* Header */
header.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
  justify-content: space-between; padding: 10px 0; background: linear-gradient(var(--sky-1), color-mix(in srgb, var(--sky-1) 85%, transparent));
}
.brand { font-weight: 900; font-size: 1.3em; cursor: pointer; letter-spacing: 0.5px; }
.brand small { display: block; font-size: 0.55em; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 3px 10px; display: inline-flex; gap: 6px; align-items: center; }
.bar { width: 70px; height: 8px; background: #eee; border-radius: 4px; overflow: hidden; display: inline-block; }
.bar i { display: block; height: 100%; background: var(--good); }
header nav { display: flex; gap: 4px; flex-wrap: wrap; width: 100%; }
header nav button { padding: 4px 12px; }

/* Title */
.title-screen { text-align: center; padding-top: 8vh; position: relative; }
.title-screen h1 { font-size: clamp(3rem, 10vw, 6rem); margin: 0; letter-spacing: 2px; text-shadow: 3px 3px 0 #fff, 6px 6px 0 var(--accent); }
.sub { font-size: 1.3em; margin: 4px 0 20px; }
.triangle-mini { font-weight: bold; margin: 16px 0; }
.title-screen .actions { justify-content: center; }
.rules li { margin: 6px 0; }

/* Map */
.belt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.belt-card {
  display: flex; gap: 12px; align-items: center; text-align: left; border-radius: var(--radius); padding: 12px; background: var(--paper);
}
.belt-card.current { outline: 3px solid var(--accent); outline-offset: 2px; }
.belt-card.locked { background: #eee; }
.belt-num { font-size: 1.8em; font-weight: 900; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--sky-2); flex: none; }
.belt-name { font-weight: bold; }
.belt-loc { color: var(--muted); }
.belt-boss { font-size: 0.9em; margin-top: 2px; }
.finished { background: #fff; border: 2px dashed var(--accent); padding: 8px 12px; border-radius: var(--radius); }
.theme-sandy .belt-num { background: #f4d79b; } .theme-sunray .belt-num { background: #ffe066; }
.theme-sunset .belt-num { background: #ffab76; } .theme-palm .belt-num { background: #a5d6a7; }
.theme-wave .belt-num { background: #90caf9; } .theme-flame .belt-num { background: #ff8a65; }
.theme-tropical .belt-num { background: #80cbc4; } .theme-driftwood .belt-num { background: #bcaaa4; }
.theme-solar .belt-num { background: #ffd54f; } .theme-encore .belt-num { background: #b39ddb; }

/* Belt */
.back { margin: 8px 0; }
.opponents { display: grid; gap: 10px; }
.opponent, .boss-card {
  display: flex; gap: 12px; align-items: center; background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.boss-card { border-color: var(--ink); flex-wrap: wrap; }
.opp-info { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 2px; }
.opp-info q { font-style: italic; color: var(--muted); }
.opp-info p { margin: 4px 0; }
.boss-actions { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; overflow: hidden; flex: none; border: 3px solid var(--ink); background: #fff; }
.avatar.big { width: 96px; height: 96px; }
.avatar.small { width: 36px; height: 36px; border-width: 2px; }
.avatar .portrait, .card-art .portrait, .hero .portrait, .finale-art .portrait { width: 100%; height: 100%; display: block; }
.portrait.painted { object-fit: cover; object-position: 50% 25%; }
.portrait.painted.card-crop { object-position: 50% 30%; }
.me-tag { display: inline-flex; align-items: center; gap: 8px; }
.hero { width: 180px; height: 180px; margin: 0 auto 12px; border-radius: 50%; overflow: hidden; border: 4px solid var(--ink); box-shadow: 0 0 50px #ffc95c; }
.finale-art { width: 220px; height: 220px; border-radius: 24px; overflow: hidden; border: 4px solid var(--ink); box-shadow: 0 0 40px #ffc23d; }
.dialog.has-face { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; }
.dialog.has-face .avatar.face { grid-row: span 3; width: 84px; height: 84px; }
.dialog.has-face .who, .dialog.has-face p, .dialog.has-face .hint { grid-column: 2; }

/* Cards */
.card {
  position: relative; width: 116px; min-height: 172px; border-radius: 10px; border: 3px solid var(--ink); background: var(--paper);
  padding: 6px; display: flex; flex-direction: column; gap: 4px; user-select: none; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); flex: none;
}
.card.el-solar { background: linear-gradient(160deg, var(--solar-bg), #fff 70%); border-color: var(--solar); }
.card.el-tide { background: linear-gradient(160deg, var(--tide-bg), #fff 70%); border-color: var(--tide); }
.card.el-gale { background: linear-gradient(160deg, var(--gale-bg), #fff 70%); border-color: var(--gale); }
.card-art { position: relative; height: 70px; margin: -6px -6px 0; border-radius: 7px 7px 0 0; overflow: hidden; border-bottom: 2px solid var(--ink); }
.card-top { position: absolute; inset: 3px 4px auto; display: flex; justify-content: space-between; align-items: center; }
.el-icon { background: rgba(255, 255, 255, 0.85); border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; font-size: 0.95em; }
.value { font-weight: 900; font-size: 1.3em; width: 30px; height: 30px; border: 2px solid #fff; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; }
.value.boosted { background: var(--accent); }
.card-name { font-weight: bold; font-size: 0.82em; line-height: 1.15; }
.tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; }
.tag { font-size: 0.68em; background: rgba(0, 0, 0, 0.08); border-radius: 4px; padding: 1px 4px; }
.count { position: absolute; bottom: 4px; right: 6px; font-size: 0.75em; font-weight: bold; }
.gem { position: absolute; top: -6px; left: 50%; width: 12px; height: 12px; transform: translateX(-50%) rotate(45deg); border: 2px solid var(--ink); background: #ddd; }
.r-rare .gem { background: #60a5fa; } .r-epic .gem { background: #c084fc; }
.r-legendary .gem { background: linear-gradient(45deg, #fde047, #f97316); }
.card.r-legendary { box-shadow: 0 0 0 2px #fde047, 0 3px 0 rgba(0, 0, 0, 0.3); }
.card.mini { width: 104px; min-height: 150px; cursor: pointer; }
.card.mini .card-art { height: 60px; }
.card.dim { opacity: 0.4; }
.card.unowned { filter: grayscale(1); opacity: 0.45; }
.card.large { width: 190px; min-height: 280px; font-size: 1.15em; }
.card.large .card-art { height: 150px; }
.card-grid { display: flex; flex-wrap: wrap; gap: 12px 10px; padding-top: 8px; }
.card-row { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 8px; }
.gallery-item { position: relative; cursor: pointer; }
.fav { position: absolute; top: 26px; right: -6px; padding: 0 6px; font-size: 0.8em; box-shadow: none; }
.fav.on { background: #fde047; }
.reveal > div { animation: flip 0.5s both; }
@keyframes flip { from { transform: rotateY(90deg) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }

/* Battle */
.battle { padding-top: 12px; }
.battle-top { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.opp-card { display: flex; gap: 10px; align-items: center; }
.opp-card small { display: block; color: var(--muted); }
.piles { display: inline-flex; gap: 10px; font-weight: bold; margin-left: 10px; }
.bubble { margin: 10px 0; background: #fff; border: 2px solid var(--ink); border-radius: 16px; padding: 8px 14px; font-style: italic; position: relative; min-height: 40px; }
.bubble::before { content: ""; position: absolute; top: -10px; left: 24px; border: 8px solid transparent; border-bottom-color: var(--ink); border-top: 0; }
.bubble.empty { visibility: hidden; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lane {
  background: rgba(255, 255, 255, 0.45); border: 2px dashed rgba(0, 0, 0, 0.2); border-radius: var(--radius); padding: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 400px;
}
.lane.target { border: 3px solid var(--accent); background: rgba(255, 255, 255, 0.75); cursor: pointer; }
.lane.target:hover { background: #fff; }
.lane.blocked { background: rgba(0, 0, 0, 0.08); }
.slot { min-height: 175px; display: grid; place-items: center; width: 100%; }
.slot.empty { border: 2px dashed rgba(0, 0, 0, 0.15); border-radius: 10px; color: var(--muted); font-size: 0.85em; }
.lane-mid { min-height: 26px; display: grid; place-items: center; }
.vs { color: var(--muted); font-weight: bold; font-size: 0.8em; }
.preview { font-weight: bold; font-size: 0.85em; padding: 2px 8px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); }
.preview.great { background: #fde047; } .preview.good { background: #bbf7d0; } .preview.ok { background: #e0f2fe; } .preview.bad { background: #fecaca; }
.card.on-board.new { animation: drop 0.25s ease-out; }
@keyframes drop { from { transform: translateY(-14px) scale(1.08); opacity: 0.4; } to { transform: none; opacity: 1; } }
.status { margin: 12px 0 6px; font-weight: bold; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 14px 4px; min-height: 200px; }
.card.in-hand { cursor: pointer; transition: transform 0.1s; }
.card.in-hand:hover { transform: translateY(-6px); }
.card.in-hand.selected { transform: translateY(-12px); outline: 4px solid var(--accent); }
.card.in-hand.idle { opacity: 0.75; cursor: default; }
.log { background: rgba(255, 255, 255, 0.6); border-radius: var(--radius); padding: 8px 12px; font-size: 0.85em; color: var(--muted); }
.log div:last-child { color: var(--ink); font-weight: bold; }

/* Results */
.result { text-align: center; }
.result h2 { font-size: 3em; margin: 20px 0 0; }
.result.won h2 { color: var(--good); } .result.lost h2 { color: var(--bad); }
.rewards { display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 12px 0; }
.reward { background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 4px 16px; font-weight: bold; }
.reward.big { background: #fde047; }
.result .card-row, .result .actions { justify-content: center; }

/* Decks / filters */
.deck-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; align-items: center; }
.deck-head { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 14px; }
.deck-head h2 { margin: 4px 0; }
.deck-bal { font-weight: bold; display: flex; gap: 12px; }
.errors { color: var(--bad); margin: 6px 0; }
.ok-msg { color: var(--good); font-weight: bold; margin: 6px 0; }
.deck-list { background: rgba(255, 255, 255, 0.4); border-radius: var(--radius); padding: 12px; min-height: 80px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.filters input { font: inherit; padding: 6px 10px; border-radius: 999px; border: 2px solid var(--ink); min-width: 180px; }

/* Shop */
.packs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.pack { background: var(--paper); border: 3px solid var(--ink); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.pack h3 { margin: 0; } .pack p { flex: 1; }
.pack.el-solar { background: var(--solar-bg); } .pack.el-tide { background: var(--tide-bg); } .pack.el-gale { background: var(--gale-bg); }
.pack.locked { opacity: 0.6; }

/* Journal / records */
.clues li { margin: 8px 0; background: var(--paper); padding: 8px 12px; border-radius: 8px; }
.bio, .talk { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 14px; margin: 10px 0; }
.bio h3 { margin: 4px 0; }
.revealed { font-weight: bold; }
.talk q { display: block; color: var(--muted); font-style: italic; }
.journal .seg { margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.stat { background: var(--paper); border-radius: 8px; padding: 8px 12px; display: flex; justify-content: space-between; }
.achievements { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.ach { background: #eee; border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; }
.ach.got { background: #fef9c3; border: 2px solid #eab308; }

/* Overlay dialogue */
#overlay { position: fixed; inset: 0; display: none; z-index: 20; background: rgba(20, 15, 40, 0.45); align-items: flex-end; justify-content: center; padding: 16px; }
#overlay.show { display: flex; }
.dialog {
  background: var(--paper); color: var(--ink); max-width: 720px; width: 100%; border: 3px solid var(--ink); border-radius: 16px; padding: 16px 20px; margin-bottom: 4vh;
  cursor: pointer; animation: rise 0.2s ease-out; max-height: 85vh; overflow: auto;
}
.dialog.wide { align-self: center; }
.dialog.boss { border-color: var(--accent); box-shadow: 0 0 0 4px #fde047; }
.dialog.bard { background: #2c2350; color: #fff6e0; font-style: italic; }
.dialog .who { font-weight: 900; font-size: 1.1em; }
.dialog p { font-size: 1.1em; line-height: 1.45; }
.dialog .hint { font-size: 0.8em; color: var(--muted); text-align: right; }
.detail { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.detail > div:last-child { flex: 1; min-width: 200px; }
.flavor { font-style: italic; color: var(--muted); }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; animation: rise 0.2s ease-out; }

@media (max-width: 640px) {
  header.top { position: static; }
  .card { width: 92px; min-height: 146px; padding: 4px; }
  .card.mini { width: 92px; }
  .card-art { height: 56px; margin: -4px -4px 0; }
  .avatar.big { width: 72px; height: 72px; }
  .dialog.has-face .avatar.face { width: 60px; height: 60px; }
  .card-name { font-size: 0.72em; }
  .value { width: 28px; height: 28px; font-size: 1.2em; }
  .lane { padding: 4px; min-height: 340px; }
  .slot { min-height: 150px; }
  .board { gap: 6px; }
  .preview { font-size: 0.72em; padding: 2px 4px; }
}

/* Typed dialogue: a blinking caret appears once the line is finished. */
.dialog p.typed { min-height: 3em; }
.dialog .caret { display: inline-block; margin-left: 6px; font-size: 0.7em; opacity: 0; color: var(--accent); }
.dialog.done .caret { opacity: 1; animation: caret-bob 0.9s ease-in-out infinite; }
@keyframes caret-bob { 50% { transform: translateY(3px); } }
.pill.mute { cursor: pointer; padding: 3px 8px; box-shadow: none; }
.slider { display: inline-flex; align-items: center; gap: 8px; }
.slider input { width: 120px; accent-color: var(--accent); }

/* Versus */
.vs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.panel { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 16px 14px; margin: 12px 0; }
.panel h3 { margin: 10px 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-weight: bold; font-size: 0.9em; }
.field input, .field select, .join-row input { font: inherit; font-weight: normal; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 9em; text-transform: uppercase; letter-spacing: 3px; font-weight: bold; }
.avatar-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar-choice { padding: 2px; border-radius: 50%; box-shadow: none; border-color: transparent; background: none; }
.avatar-choice.on { border-color: var(--accent); background: #fff; }
.banner { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); padding: 8px 14px; margin: 10px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: #fff4d6; border-color: #e0a21a; }
.find-head { display: flex; justify-content: space-between; align-items: center; }
.lobby-list { display: grid; gap: 8px; }
.lobby { display: flex; align-items: center; gap: 12px; border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: #fff; }
.lobby code, .room-code { font-weight: 900; letter-spacing: 3px; }
.room-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.code-box { background: #fff; border: 3px solid var(--ink); border-radius: var(--radius); padding: 8px 16px; text-align: center; }
.room-code { font-size: 2.4em; color: var(--accent); }
.code-box .actions { justify-content: center; margin: 4px 0 0; }
.seats { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; margin: 16px 0; }
.seat { background: var(--paper); border: 3px solid var(--line); border-radius: 16px; padding: 14px; width: 210px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.seat.ready { border-color: var(--good); }
.seat.empty { border-style: dashed; opacity: 0.8; }
.avatar.placeholder { display: grid; place-items: center; font-size: 2em; font-weight: 900; color: var(--muted); }
.vs-mark { font-size: 2em; font-weight: 900; color: var(--accent); }
.turn-timer { font-weight: 900; padding: 2px 10px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); min-width: 4.5em; text-align: center; }
.turn-timer:empty { display: none; }
.turn-timer.mine { background: #e0f2fe; }
.turn-timer.low { background: #fecaca; animation: caret-bob 0.6s ease-in-out infinite; }
.emotes { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
