:root {
  --bg: #0d1512;
  --panel: #14201b;
  --panel-2: #1b2b24;
  --line: #2a3f35;
  --text: #e6efe9;
  --muted: #8ea89a;
  --accent: #3fd17f;
  --accent-ink: #062a15;
  --warn: #f2b84b;
  --danger: #ff6b6b;
  --radius: 12px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #17352a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 650; cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 5px 10px; font-size: 13px; }
button:hover { filter: brightness(1.08); }
input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
input:focus { border-color: var(--accent); }
kbd { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

/* Login */
.card {
  width: min(380px, calc(100% - 32px)); margin: 12vh auto 0; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
}
.card h1 { margin: 0; font-size: 26px; display: flex; align-items: center; gap: 10px; }
.card .sub { margin: 4px 0 20px; color: var(--muted); }
.card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.card label input { margin-top: 4px; font-size: 15px; color: var(--text); }
.card .row { display: flex; gap: 8px; margin-top: 6px; }
.card .row button { flex: 1; }
.gem {
  width: 18px; height: 18px; background: var(--accent); display: inline-block;
  transform: rotate(45deg); border-radius: 3px; box-shadow: 0 0 18px #3fd17f88;
}

/* Game layout */
#game {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px;
  max-width: 1200px; margin: 0 auto; padding: 20px 16px;
}
.stage { min-width: 0; }
.screen-wrap {
  position: relative; width: 100%; aspect-ratio: 3 / 2; background: #000;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
}
#screen { width: 100%; height: 100%; display: block; }
#tags { position: absolute; inset: 0; pointer-events: none; }
.tag {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap;
  font-size: clamp(9px, 1.4vw, 13px); font-weight: 700; padding: 1px 6px; border-radius: 6px;
  background: #0d1512cc; color: #fff; border: 1px solid #3fd17f66;
}
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: #000c; color: var(--text); font-weight: 600; padding: 20px;
}
.statusbar { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.on { color: var(--accent); border-color: #3fd17f66; }
.pill.off { color: var(--warn); }
.keys { margin-top: 10px; color: var(--muted); font-size: 13px; }
.keys summary { cursor: pointer; }
.keys h3 { margin: 14px 0 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kb-help { margin: 8px 0; line-height: 1.5; }
.kb-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; }
.kb-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px; }
.kb-name { color: var(--text); font-size: 13px; }
.keys button.kb-key { min-width: 54px; padding: 4px 8px; font: 500 12px var(--mono); border-radius: 6px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.kb-key:hover { border-color: var(--accent); }
.kb-key.unset { color: var(--muted); }
.kb-key.listening { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 2px rgba(63, 209, 127, .25); }
.kb-reset { margin: 6px 0; }

/* Sidebar */
.side {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 40px);
}
.side h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0 8px; display: flex; gap: 8px; align-items: center; }
.count { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 7px; font-size: 12px; letter-spacing: 0; }
#players { list-style: none; margin: 0 0 14px; padding: 0; max-height: 40vh; overflow: auto; }
#players li { padding: 7px 8px; border-radius: 8px; display: grid; gap: 1px; }
#players li + li { border-top: 1px solid var(--line); }
#players .who { font-weight: 650; display: flex; gap: 6px; align-items: center; }
#players .where { font-size: 12px; color: var(--muted); }
#players .here { font-size: 11px; color: var(--accent-ink); background: var(--accent); border-radius: 5px; padding: 0 5px; font-weight: 700; }
#players .me .who::after { content: "you"; font-size: 11px; color: var(--muted); font-weight: 500; }
#chat-log { flex: 1; min-height: 120px; overflow: auto; font-size: 14px; padding-right: 4px; }
#chat-log p { margin: 0 0 6px; overflow-wrap: anywhere; }
#chat-log b { color: var(--accent); }
#chat-log .sys { color: var(--muted); font-style: italic; }
#chat-form { margin-top: 8px; }

/* Toasts */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 10; }
.toast { background: var(--panel-2); border: 1px solid #3fd17f66; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 30px #0008; animation: pop .2s ease-out; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

/* Touch controls (phones / tablets) */
.touch { display: none; }
@media (pointer: coarse) {
  .touch {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
    margin-top: 14px; user-select: none; -webkit-user-select: none; touch-action: none;
  }
  .keys { display: none; }
}
.touch button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 0; touch-action: none; }
.touch button.pressed { background: var(--accent); color: var(--accent-ink); }
.dpad { display: grid; grid-template: repeat(3, 48px) / repeat(3, 48px); }
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; } .dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }
.mid { display: flex; gap: 8px; justify-content: center; }
.pillbtn { padding: 6px 12px !important; font-size: 12px; border-radius: 99px; }
.ab { display: flex; gap: 12px; align-items: center; }
.ab button { width: 60px; height: 60px; border-radius: 50%; font-weight: 800; font-size: 18px; }
.ab .a { transform: translateY(-16px); }

@media (max-width: 860px) {
  #game { grid-template-columns: 1fr; padding: 10px; }
  .side { max-height: none; }
  #chat-log { max-height: 220px; }
}

/* ---------- Icon buttons ---------- */
.icon-btn {
  width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center;
  background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 10px;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--panel-2); filter: none; }
.icon-btn:focus-visible, .vol input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Volume ---------- */
.vol { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding-right: 10px; border: 1px solid var(--line); border-radius: 10px; }
.vol .icon-btn { border: 0; }
.vol .spk { fill: currentColor; stroke: none; }
.vol .x { display: none; }
.vol[data-level="0"] .w1, .vol[data-level="0"] .w2 { display: none; }
.vol[data-level="0"] .x { display: inline; }
.vol[data-level="1"] .w2 { display: none; }
.vol input[type=range] {
  -webkit-appearance: none; appearance: none; width: 96px; height: 4px; padding: 0; border: 0; border-radius: 99px; cursor: pointer;
  background: linear-gradient(to right, var(--accent) var(--fill, 70%), var(--line) var(--fill, 70%));
}
.vol input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 0; box-shadow: 0 1px 4px #0006;
}
.vol input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 0; }
.vol input[type=range]::-moz-range-track { background: transparent; }

/* ---------- Player / fullscreen ---------- */
.player { position: relative; }
.fs-bar, .fs-chat { display: none; }

.player.is-fs {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: grid; place-items: center; cursor: none;
}
.player.is-fs.show-ui { cursor: default; }
.player.is-fs .screen-wrap {
  width: min(100vw, 150vh); height: auto; aspect-ratio: 3 / 2;
  border: 0; border-radius: 0;
}
.player.is-fs .tag { font-size: clamp(11px, 1.2vw, 18px); }

/* Top-right controls: appear on mouse movement */
.player.is-fs .fs-bar {
  display: flex; gap: 8px; align-items: center; position: absolute; top: 16px; right: 16px;
  padding: 6px; border-radius: 14px; background: #0d1512cc; backdrop-filter: blur(8px);
  border: 1px solid #ffffff1a; opacity: 0; transform: translateY(-6px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.player.is-fs.show-ui .fs-bar { opacity: 1; transform: none; pointer-events: auto; }
.fs-bar .vol { border-color: transparent; }

/* Chat overlay */
.player.is-fs .fs-chat {
  display: flex; flex-direction: column; gap: 6px; position: absolute; left: 16px; bottom: 16px;
  width: min(420px, calc(100vw - 32px)); pointer-events: none;
}
#fs-chat-log { display: flex; flex-direction: column; gap: 3px; max-height: 40vh; overflow: hidden; justify-content: flex-end; }
#fs-chat-log p {
  margin: 0; padding: 4px 10px; border-radius: 8px; width: fit-content; max-width: 100%;
  background: #0d1512b3; color: #fff; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere;
  text-shadow: 0 1px 2px #000; transition: opacity .6s;
}
#fs-chat-log p b { color: var(--accent); }
#fs-chat-log p.sys { color: #c9d6cf; font-style: italic; }
#fs-chat-log p.faded { opacity: 0; }
#fs-chat-form { display: none; }
.fs-hint { font-size: 12px; color: #ffffff99; text-shadow: 0 1px 2px #000; transition: opacity .3s; }
.fs-hint kbd { color: #fff; }
.player.is-fs:not(.show-ui):not(.chat-open) .fs-hint { opacity: 0; }

/* Chat open: show full history with a backdrop, plus the input */
.player.chat-open .fs-chat { pointer-events: auto; }
.player.chat-open #fs-chat-log {
  max-height: 50vh; overflow-y: auto; padding: 8px; border-radius: 12px; background: #0d1512cc; backdrop-filter: blur(8px);
}
.player.chat-open #fs-chat-log p { background: transparent; padding: 1px 2px; }
.player.chat-open #fs-chat-log p.faded { opacity: 1; }
.player.chat-open #fs-chat-form { display: block; }
.player.chat-open .fs-hint { display: none; }
#fs-chat-input { background: #0d1512e6; border-color: #3fd17f88; color: #fff; backdrop-filter: blur(8px); }

/* Toasts while fullscreen */
.player.is-fs #toasts { position: absolute; top: 16px; }

/* Touch controls float over the game in fullscreen on phones */
@media (pointer: coarse) {
  .player.is-fs .touch {
    position: absolute; left: 12px; right: 12px; bottom: 12px; margin: 0; opacity: .55;
  }
  .player.is-fs .fs-chat { bottom: auto; top: 16px; }
  .player.is-fs .fs-bar { opacity: 1; pointer-events: auto; transform: none; }
}
.version { margin: 6px 0 0; font-size: 11px; color: var(--muted); opacity: .7; }

/* ---------- In-game style menus (talk to a trainer / battle requests) ---------- */
.screen-wrap { container-type: inline-size; }
.gmenu {
  position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: flex-end;
  padding: 3cqw; background: linear-gradient(to top, #0006, transparent 55%); z-index: 5;
  animation: gmenu-in .14s ease-out;
}
@keyframes gmenu-in { from { opacity: 0; } }
.gmenu-box {
  min-width: 34cqw; max-width: 60cqw; background: #f8f8f8; color: #303030;
  border: .7cqw solid #5a6b7b; border-radius: 1.6cqw; padding: 2cqw 2.6cqw 1.6cqw;
  box-shadow: inset 0 0 0 .5cqw #fff, inset 0 0 0 .9cqw #d8dee6, 0 1.2cqw 3cqw #0007;
  font-weight: 700; animation: gmenu-pop .16s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes gmenu-pop { from { transform: translateY(1.5cqw) scale(.97); } }
.gmenu-title { font-size: 3.4cqw; color: #1f7a4a; letter-spacing: .02em; }
.gmenu-text { font-size: 2.7cqw; color: #505860; margin: .6cqw 0 1.2cqw; line-height: 1.3; }
.gmenu-text:empty { display: none; }
.gmenu-list { list-style: none; margin: 0; padding: 0; }
.gmenu-list li {
  font-size: 3.2cqw; padding: .55cqw 0 .55cqw 3.6cqw; position: relative; cursor: pointer; border-radius: .8cqw;
}
.gmenu-list li.sel::before {
  content: ""; position: absolute; left: .9cqw; top: 50%; transform: translateY(-50%);
  border-left: 1.5cqw solid #303030; border-top: 1cqw solid transparent; border-bottom: 1cqw solid transparent;
}
.gmenu-list li:hover { background: #e9eef3; }
.gmenu-foot { font-size: 2.2cqw; color: #8a949e; text-align: right; margin-top: .4cqw; min-height: 1em; }
.gmenu-foot:empty { min-height: 0; margin: 0; }

/* Graphics controls */
.gfx {
  height: 32px; padding: 0 28px 0 10px; font: inherit; font-size: 13px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239fb3a8' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.gfx:hover { border-color: #3fd17f66; }
.gfx:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#btn-color.on { color: var(--accent); border-color: #3fd17f66; background: #3fd17f1a; }

/* Side actions */
.side-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 99px; padding: 7px 13px; font-size: 13px; font-weight: 600;
}
.chip:hover { border-color: #3fd17f66; filter: none; }
.chip-ico { font-size: 14px; }
.badge {
  min-width: 18px; padding: 0 6px; height: 18px; line-height: 18px; text-align: center; border-radius: 99px;
  font-size: 11px; font-weight: 700; background: var(--accent); color: var(--accent-ink);
}
.badge.live { background: var(--warn); }

/* Panel modal */
.panel-modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: #050a08cc; backdrop-filter: blur(4px);
}
.panel-card {
  width: min(820px, 100%); max-height: min(720px, calc(100vh - 32px)); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 60px #0008; overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; }
.seg-btn { background: transparent; color: var(--muted); padding: 7px 14px; font-size: 14px; border-radius: 8px; }
.seg-btn.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg-btn:hover { filter: none; color: var(--text); }
.panel-body { padding: 18px 18px 22px; overflow: auto; }
.panel-body h3 { margin: 0 0 4px; font-size: 17px; }
.panel-body p { margin: 4px 0 0; }
.panel-body .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font: inherit; outline: none; min-width: 0;
}
.field:focus { border-color: var(--accent); }
select.field { cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.empty { text-align: center; padding: 34px 12px 20px; }
.empty .row { justify-content: center; margin-top: 18px; }
.empty-icon { font-size: 42px; margin-bottom: 6px; }
.empty-line { padding: 8px 2px; }

.tour-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.entrants { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.entrants li { display: flex; align-items: center; gap: 9px; padding: 9px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tag-pill { margin-left: auto; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tag-pill.you { color: var(--accent); border-color: #3fd17f55; }

.champ { display: flex; align-items: center; gap: 14px; padding: 14px 18px; margin-bottom: 18px; border-radius: 14px;
  background: linear-gradient(120deg, #3a3012, #1f2a1d); border: 1px solid #f2b84b66; }
.champ-cup { font-size: 34px; }
.champ-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--warn); font-weight: 700; }
.champ-name { font-size: 22px; font-weight: 750; }

.bracket { display: flex; gap: 22px; overflow-x: auto; padding-bottom: 6px; }
.round { display: flex; flex-direction: column; min-width: 210px; flex: 1 0 210px; }
.round-name { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.round-cards { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; flex: 1; }
.match { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.match.mine { border-color: #3fd17f77; }
.match.live { border-color: var(--warn); box-shadow: 0 0 0 1px #f2b84b44; }
.seat { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.seat + .seat { border-top: 1px solid var(--line); }
.seat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-name.tbd { color: var(--muted); font-style: italic; }
.seat.won .seat-name { font-weight: 700; }
.seat.lost { opacity: .5; }
.seat-ok { font-size: 11px; font-weight: 700; color: var(--accent); }
.seat-check { color: var(--accent); font-weight: 800; }
.match-foot { padding: 6px 12px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.match.live .match-foot { color: var(--warn); }

.post { padding: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; }
.post-grid { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr auto; gap: 8px; margin-top: 10px; }
.section-title { margin: 22px 0 10px !important; }
.listings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.listing { display: grid; grid-template-columns: 1.3fr 1fr auto; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.listing.mine { border-color: #3fd17f55; }
.l-mon { font-weight: 700; }
.l-sub, .l-note { font-size: 12.5px; color: var(--muted); }
.l-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

@media (max-width: 640px) {
  .post-grid { grid-template-columns: 1fr; }
  .listing { grid-template-columns: 1fr; gap: 8px; }
  .l-act { justify-self: start; }
}
select.field {
  appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239fb3a8' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
