/* The play app, in the website's Blockout look: warm grey grid, dark ink, light panels with thick
   edges and hard offset shadows, an orange accent, Bungee for display and Bricolage Grotesque for
   text (client/fonts/fonts.css). */
:root {
  --bg: #c9c7be;
  --grid-minor: rgba(60, 56, 46, .10);
  --grid-major: rgba(242, 140, 40, .55);
  --panel: #f3f1ea;
  --panel-2: #e6e3d9;
  --line: #22201c;
  --text: #22201c;
  --muted: #4a463d;
  --accent: #f28c28;
  --danger: #d93a2b;
  --ok: #2f8f4e;
  --shadow: #22201c;
  --radius: 14px;
  --display: "Bungee", system-ui, sans-serif;
  font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--text); overflow: hidden; }
body {
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-major) 2px, transparent 2px),
    linear-gradient(90deg, var(--grid-major) 2px, transparent 2px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-size: 128px 128px, 128px 128px, 32px 32px, 32px 32px;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--text); font-weight: 800; text-underline-offset: 3px; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; }

/* ---------- generic UI ---------- */
/* "safe" keeps the top of a screen taller than the window reachable instead of cut off. */
.screen { position: absolute; inset: 0; display: flex; align-items: center; align-items: safe center; justify-content: center; overflow: auto; padding: 24px; }
.panel { background: var(--panel); border: 3px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 8px 8px 0 var(--shadow); }
.title { font: 400 44px/1 var(--display); margin: 0 0 8px; text-shadow: 3px 3px 0 var(--accent); }
.title span { color: var(--text); }
.subtitle { color: var(--muted); margin: 0 0 20px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { height: 10px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }

input[type=text], input[type=password], input[type=number], select {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 9px 11px; outline: none; min-width: 0; color: var(--text);
}
input::placeholder { color: var(--muted); opacity: .6; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
input.code { font-family: var(--display); text-transform: uppercase; letter-spacing: 3px; }

.btn {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font-weight: 800; white-space: nowrap; color: var(--text); box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover:not(:disabled) { background: #fffdf7; }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--line); color: var(--panel); border-color: var(--line); box-shadow: 4px 4px 0 var(--accent); }
.btn.primary:hover:not(:disabled) { background: #3a3630; }
.btn.primary:active:not(:disabled) { box-shadow: 1px 1px 0 var(--accent); }
.btn.danger { color: var(--danger); }
.btn.big { padding: 13px 22px; font-size: 17px; }
.btn.tiny { padding: 3px 8px; font-size: 12px; box-shadow: 2px 2px 0 var(--shadow); }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs .btn.active { background: var(--accent); }

.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: var(--panel-2); color: var(--muted); border: 1.5px solid var(--line); vertical-align: middle; }
.badge.host { background: var(--accent); color: var(--text); }
.badge.off { color: var(--danger); }

h2 { font: 400 20px/1.15 var(--display); }

/* ---------- home ---------- */
.host-form { border-top: 2px dashed var(--grid-major); padding-top: 14px; margin-top: 6px; }
.host-form h2 { font-size: 16px; margin: 0; }
.host-form p { margin: 0; }
.form-error { color: var(--danger); font-size: 14px; font-weight: 600; line-height: 1.4; margin: 0; }
.form-error:empty { display: none; }
.inspect-host { position: fixed; left: 0; top: 0; width: 0; height: 0; overflow: hidden; visibility: hidden; }

.home { width: min(480px, 100%); }
.home .panel { padding: 24px; }

/* ---------- lobby ---------- */
.lobby { width: min(1100px, 100%); display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.lobby-head { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.room-code { font: 400 32px/1 var(--display); letter-spacing: 4px; text-shadow: 3px 3px 0 var(--accent); }
.teams { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.team { border: 3px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.team.locked { opacity: .45; cursor: not-allowed; }
.team.mine { box-shadow: 5px 5px 0 var(--team, var(--accent)); }
.team-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--team, var(--muted)); color: #fff; }
.team-head .name { font: 400 17px/1.1 var(--display); flex: 1; }
.team-head .score { font: 400 22px/1 var(--display); }
.team-head .muted { color: rgba(255, 255, 255, .85); }
.team ul { list-style: none; margin: 0; padding: 6px 12px 12px; min-height: 60px; }
.team li, .plist li { padding: 5px 0; display: flex; gap: 6px; align-items: center; border-top: 1px dashed var(--grid-major); }
.team li:first-child, .plist li:first-child { border-top: 0; }
.team li.me .pname, .plist li.me .pname { font-weight: 800; }
.pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist { list-style: none; margin: 0; padding: 0; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.result { border: 2px solid var(--line); border-left: 8px solid var(--accent); padding: 10px 14px; background: var(--panel); border-radius: 10px; font-weight: 600; }
.result.error { border-left-color: var(--danger); }

.chat { display: flex; flex-direction: column; height: 360px; }
.chat-log { flex: 1; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 3px; padding-right: 4px; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log b { color: var(--who, var(--text)); }
.chat form { display: flex; gap: 6px; margin-top: 8px; }
.chat form input { flex: 1; }

/* ---------- match ---------- */
.game-root { position: absolute; inset: 0; }
/* Clicks pass through HUDs to the game canvas; add class "interactive" to anything clickable. */
.game-hud { position: absolute; inset: 0; pointer-events: none; }
.game-hud .interactive { pointer-events: auto; }
.overlay { position: absolute; inset: 0; pointer-events: none; }
.overlay .interactive { pointer-events: auto; }

.scorebar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: none; z-index: 5; }
.scorebar .ts { min-width: 70px; text-align: center; padding: 4px 12px; border-radius: 10px; font: 400 22px/1.1 var(--display); color: #fff; background: var(--team); border: 3px solid var(--line); box-shadow: 3px 3px 0 var(--shadow); }
.scorebar .ts small { display: block; font: 800 10px/1.2 "Bricolage Grotesque", system-ui, sans-serif; letter-spacing: 1px; text-transform: uppercase; opacity: .9; }
.scorebar .ts.mine { box-shadow: 3px 3px 0 var(--accent); }

.modal-bg { position: absolute; inset: 0; background: rgba(34, 32, 28, .55); display: flex; align-items: center; justify-content: center; pointer-events: auto; z-index: 20; }
.modal { width: min(900px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; }
.modal h2 { margin: 0 0 4px; }
.modal .teams .team { cursor: pointer; transition: transform .08s; }
.modal .teams .team:hover { transform: translate(-2px, -2px); }

.scoreboard table { width: 100%; border-collapse: collapse; font-size: 14px; }
.scoreboard th { text-align: left; color: var(--muted); font-weight: 800; font-size: 12px; padding: 4px 6px; }
.scoreboard td { padding: 4px 6px; border-top: 1px dashed var(--grid-major); }
.scoreboard td.num, .scoreboard th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard tr.me td { font-weight: 800; }

/* Over the game, text sits on ink chips so it reads against any scene. */
.game-chat { position: absolute; left: 12px; bottom: 12px; width: min(420px, 60vw); z-index: 10; pointer-events: none; }
.game-chat .lines { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; font-size: 14px; font-weight: 600; }
.game-chat .lines div { background: rgba(34, 32, 28, .78); color: #f3f1ea; padding: 2px 8px; border-radius: 6px; transition: opacity .6s; }
.game-chat .lines div.old { opacity: 0; }
.game-chat.open .lines div.old { opacity: 1; }
.game-chat.open { pointer-events: auto; }
.game-chat.open .lines { max-height: 40vh; overflow-y: auto; }
.game-chat .sys { color: #d8d4c8; font-style: italic; }
.game-chat b { color: var(--who, #fff); }
.game-chat form { display: none; margin-top: 6px; }
.game-chat.open form { display: flex; }
.game-chat form input { flex: 1; }

.hint { position: absolute; right: 12px; bottom: 12px; font-size: 12px; font-weight: 600; color: #f3f1ea; text-shadow: 0 1px 2px #22201c; text-align: right; pointer-events: none; z-index: 5; line-height: 1.8; }
.kbd { display: inline-block; padding: 0 6px; border: 1.5px solid var(--line); border-radius: 5px; font-size: 11px; font-weight: 800; background: var(--panel); color: var(--text); text-shadow: none; box-shadow: 1px 1px 0 var(--shadow); }

.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 400 22px var(--display); color: var(--text); }

/* ---------- games from GitHub ---------- */
.match-col { position: absolute; inset: 0; display: flex; flex-direction: column; }
.match-stage { position: relative; flex: 1; min-height: 0; }
.game-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: transparent; }
.unreviewed { position: relative; flex: none; padding: 7px 44px; background: var(--line); border-bottom: 3px solid var(--accent); color: var(--panel); font-size: 13px; line-height: 1.45; text-align: center; }
.unreviewed-close { position: absolute; top: 5px; right: 8px; width: 28px; height: 28px; padding: 0; border: 2px solid transparent; border-radius: 8px; background: none; color: var(--accent); font: 800 20px/1 system-ui, sans-serif; cursor: pointer; }
.unreviewed-close:hover, .unreviewed-close:focus-visible { border-color: var(--accent); }
.unreviewed a { color: var(--accent); text-decoration-color: var(--accent); }
.unreviewed-sub { font-size: 12px; opacity: .8; }
.first-look { position: fixed; inset: 0; background: rgba(34, 32, 28, .6); display: flex; align-items: center; justify-content: center; z-index: 150; }
.first-look .modal { width: min(520px, calc(100% - 32px)); }
.first-look p { margin: 0; font-size: 16px; line-height: 1.5; }

#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; pointer-events: none; align-items: center; }
.toast { background: var(--line); color: var(--panel); font-weight: 800; padding: 10px 16px; border-radius: 12px; transition: opacity .4s; border: 2px solid var(--line); }
.toast.error { border-color: var(--danger); box-shadow: 4px 4px 0 var(--danger); }
.toast.ok { box-shadow: 4px 4px 0 var(--accent); }
.toast.out { opacity: 0; }

.conn-banner { position: fixed; top: 0; left: 0; right: 0; background: var(--danger); color: #fff; text-align: center; padding: 6px; font-weight: 800; z-index: 200; border-bottom: 3px solid var(--line); }

@media (max-width: 820px) {
  .lobby { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
