/* TetriNET Web — themed (light default, dark optional) */

:root {
  --font-ui: "IBM Plex Mono", ui-monospace, monospace;
  --font-display: "Silkscreen", var(--font-ui);
  --font-block: "Nunito", system-ui, sans-serif; /* rounded, very legible */
}

/* ---- DARK theme ---- */
html[data-theme="dark"] {
  --bg: #0a0c16;
  --panel: #141829;
  --panel-2: #10131f;
  --line: #2a3050;
  --text: #c9d1f0;
  --dim: #7a84b0;
  --amber: #f0b429;
  --amber-ink: #1a1405;
  --danger: #e5484d;
  --ok: #3dd68c;
  --field-bg: #10131f;
  --grid-line: rgba(42,48,80,0.35);
  --special-bg: #1c2138;
  --special-fg: #ffd54a;
}

/* ---- LIGHT theme ---- */
html[data-theme="light"] {
  --bg: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f4f6fb;
  --line: #cdd4e4;
  --text: #1f2740;
  --dim: #5a6485;
  --amber: #e0930a;
  --amber-ink: #fff8e8;
  --danger: #d23437;
  --ok: #1aa367;
  --field-bg: #f7f9fd;
  --grid-line: rgba(120,132,170,0.28);
  --special-bg: #2b3252;
  --special-fg: #ffd54a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* ---------- overlays / cards ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 24, 0.6);
  backdrop-filter: blur(3px);
}

.join-card, .modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.join-card {
  padding: 40px 44px;
  width: min(380px, 92vw);
  text-align: center;
}

.modal-card {
  padding: 28px 30px;
  width: min(440px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-card.wide { width: min(560px, 95vw); }

.logo {
  font-family: var(--font-display);
  font-size: 34px;
  letter-spacing: 2px;
  color: var(--text);
}
.logo span { color: var(--amber); }
.logo.small { font-size: 16px; }

.tagline { color: var(--dim); font-size: 12px; margin: 6px 0 26px; letter-spacing: 1px; }

.join-label {
  display: block; text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 2px;
  color: var(--dim); margin-bottom: 6px;
}

#nick-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  padding: 10px 12px;
  margin-bottom: 14px;
  outline: none;
}
#nick-input:focus { border-color: var(--amber); }

.join-error { color: var(--danger); font-size: 12px; margin-top: 12px; min-height: 1em; }

.modal-title {
  font-family: var(--font-display);
  font-size: 16px; letter-spacing: 1px;
  color: var(--amber);
  margin-bottom: 4px;
}
.modal-sub { color: var(--dim); font-size: 12px; margin-bottom: 18px; }

/* ---------- buttons ---------- */

.btn {
  font-family: var(--font-ui);
  font-size: 13px; font-weight: 600; letter-spacing: 1px;
  padding: 9px 18px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--dim); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.btn-amber { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.join-card .btn-amber { width: 100%; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-ghost { color: var(--dim); }

/* ---------- header ---------- */

header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#status-line { flex: 1; color: var(--dim); font-size: 13px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- main arena ---------- */

main {
  display: grid;
  grid-template-columns: auto auto 1fr;
  grid-template-areas: "myside center opponents";
  gap: 18px;
  padding: 18px;
  margin: 0;
  align-items: start;
  overflow-x: hidden;
}

#my-side { grid-area: myside; }
#center-col { grid-area: center; display: flex; flex-direction: column; gap: 12px; width: 248px; flex: none; }
#opponents { grid-area: opponents; display: grid; gap: 12px; align-content: start; }

.field-frame {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px;
}
.field-title {
  font-family: var(--font-display);
  font-size: 11px; color: var(--amber);
  margin-bottom: 6px; letter-spacing: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

canvas { display: block; background: var(--field-bg); }
#next-canvas { max-width: 100%; margin: 0 auto; }

.countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 64px;
  color: var(--amber); pointer-events: none;
}
.field-banner {
  position: absolute; left: 8px; right: 8px; top: 45%;
  text-align: center; font-family: var(--font-display);
  font-size: 18px; padding: 10px 4px;
  background: var(--panel); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  pointer-events: none;
}
.field-banner.lost { color: var(--danger); }
.field-banner.won { color: var(--ok); }

/* ---------- center column ---------- */

.stat-row { display: flex; gap: 8px; }
.stat-block {
  flex: 1; min-width: 0;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 9px;
}
.stat-label, .panel-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--dim); margin-bottom: 4px;
  white-space: nowrap; overflow: hidden;
}
.stat-value { font-family: var(--font-display); font-size: 22px; color: var(--text); }

.panel { background: var(--panel); border: 1px solid var(--line); padding: 10px 12px; }

#inventory { display: flex; gap: 4px; flex-wrap: wrap; min-height: 30px; align-items: center; }
.inv-slot {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-block); font-weight: 900; font-size: 16px;
  background: var(--special-bg); border: 1px solid var(--line);
  color: var(--special-fg);
}
.inv-slot.first { border-color: var(--amber); box-shadow: 0 0 8px rgba(240,180,41,0.35); }
.inv-empty { color: var(--dim); font-size: 11px; }

#attacks-log {
  height: 200px; overflow-y: auto;
  font-size: 12px; line-height: 1.55;
}
#attacks-log div { margin-bottom: 2px; word-break: break-word; }
#attacks-log .atk { color: var(--danger); }
#attacks-log .def { color: var(--ok); }
#attacks-log .neu { color: var(--dim); }

/* ---------- legend (larger) ---------- */

#legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 12px; color: var(--text);
}
#legend .lg { display: inline-flex; align-items: center; gap: 7px; }
#legend .chip {
  width: 22px; height: 22px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--amber);
  background: var(--special-bg);
  color: var(--special-fg);
  font-family: var(--font-block); font-weight: 900; font-size: 13px;
}

/* ---------- opponents ---------- */

.opp { background: var(--panel); border: 1px solid var(--line); padding: 6px; position: relative; }
.opp .field-title { color: var(--text); font-size: 10px; }
.opp .field-title .slot-num { color: var(--amber); }
.opp.dead canvas { opacity: 0.35; }
.opp.dead .field-title { color: var(--dim); }

/* ---------- partyline ---------- */

#partyline { margin: 0 0 24px; padding: 0 18px; }
.pl-header {
  font-family: var(--font-display); font-size: 11px; color: var(--amber);
  letter-spacing: 3px; border-bottom: 1px solid var(--amber); padding-bottom: 4px; margin-bottom: 6px;
}
#chat-log {
  height: 120px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 10px; font-size: 13px;
}
#chat-log .nick { color: var(--amber); }
#chat-log .info { color: var(--dim); font-style: italic; }
#chat-log div { margin-bottom: 2px; word-break: break-word; }
.pl-input-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-top: none;
  background: var(--panel); padding: 6px 10px;
}
.pl-prompt { color: var(--amber); font-weight: 600; }
#chat-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: var(--font-ui); font-size: 13px; }

/* ---------- config rows (keys + settings modals) ---------- */

.config-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.config-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.config-row label { font-size: 13px; color: var(--text); }
.config-row .hint { font-size: 11px; color: var(--dim); }

.key-bind {
  min-width: 96px; text-align: center;
  font-family: var(--font-ui); font-size: 13px; font-weight: 600;
  padding: 7px 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  cursor: pointer;
}
.key-bind.listening { border-color: var(--amber); color: var(--amber); }

.config-row input[type="number"] {
  width: 80px; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); font-family: var(--font-ui); font-size: 13px; padding: 6px 8px; text-align: right;
}
.config-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--amber); }

.settings-section {
  font-family: var(--font-display); font-size: 11px; color: var(--dim);
  letter-spacing: 1px; margin: 14px 0 4px; padding-top: 8px;
}
.freq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- winlist ---------- */
.winlist-body { margin: 18px 0; text-align: left; max-height: 50vh; overflow-y: auto; }
.winlist-row { display: flex; justify-content: space-between; padding: 4px 2px; border-bottom: 1px solid var(--line); }
.winlist-row .w { color: var(--amber); font-family: var(--font-display); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  main {
    grid-template-columns: 1fr;
    grid-template-areas: "myside" "center" "opponents";
    justify-items: center;
  }
  #center-col { width: 100%; max-width: 420px; }
  #opponents { width: 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
