:root {
  --bg: #0f1522;
  --panel: #182133;
  --panel-2: #212c42;
  --line: #2e3b55;
  --text: #e8ecf4;
  --muted: #93a0b8;
  --accent: #e0a23a;
  --accent-text: #1c1405;
  --danger: #e2685f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

h1, h2 { margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 22px; margin-bottom: 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.logo { font-size: 34px; letter-spacing: -.02em; font-weight: 800; }
.logo span { color: var(--accent); }

button, input {
  font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); padding: 9px 14px;
}
button { cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.small { padding: 5px 10px; font-size: 12px; }
input { background: var(--bg); min-width: 0; }
input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.row > input { flex: 1; }

.screen { position: fixed; inset: 0; }
.screen.centered { display: grid; place-items: center; padding: 16px; overflow: auto; }

.card {
  width: min(380px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px; display: flex; flex-direction: column; gap: 10px;
}
.card.wide { width: min(480px, 100%); gap: 0; }
.card label { font-size: 12px; color: var(--muted); margin-top: 8px; }
#join-code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; }

.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.room-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel-2); border-radius: 8px; padding: 8px 10px;
}
.room-list .empty { background: none; color: var(--muted); padding: 4px 0; }
.room-list .code { font-weight: 700; letter-spacing: .12em; }

/* ---------- game layout ---------- */

#screen-game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "stage panel" "actions panel";
}
#stage { grid-area: stage; position: relative; min-height: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#actions {
  grid-area: actions; padding: 8px 14px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#status { min-height: 22px; text-align: center; font-weight: 600; }
#status.bad { color: var(--danger); }
#status.good { color: #7fd6a0; }
#secret-form { width: min(420px, 100%); display: flex; flex-direction: column; gap: 6px; }
#secret-form label { font-size: 13px; font-weight: 600; }
#secret-input { text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }
#secret-form .hint { margin: 0; }
#secret-note { background: var(--panel-2); border: 1px dashed var(--accent); border-radius: 8px; padding: 7px 10px; }
#secret-note strong { color: var(--accent); letter-spacing: .08em; }
#buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

#panel {
  grid-area: panel; background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px; display: flex; flex-direction: column; gap: 12px; min-height: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-code { font-size: 24px; font-weight: 800; letter-spacing: .14em; }

#players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#players li {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid transparent; border-radius: 8px; padding: 8px 10px;
}
#players li.turn { border-color: var(--accent); }
#players li.offline .pname { opacity: .5; }
#players .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#players .ptag { font-size: 11px; color: var(--muted); }
#players .pscore { font-weight: 800; font-variant-numeric: tabular-nums; }
#players li.winner .pscore { color: var(--accent); }

#log {
  list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto;
  font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px;
}
#log li:last-child { color: var(--text); }

/* ---------- modals, toast ---------- */

.modal { position: fixed; inset: 0; background: rgba(5, 8, 14, .7); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal h2 { margin-top: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 17px; }
.letter-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 6px 0; }
.letter-grid button { padding: 9px 0; background: #f0e4c6; color: #2a2114; border-color: #f0e4c6; font-weight: 800; }
.letter-grid button.on { background: var(--accent); border-color: #fff; }

#toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 30;
  background: var(--danger); color: #fff; padding: 9px 16px; border-radius: 8px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
#offline {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line); padding: 7px 14px; border-radius: 8px;
}

/* ---------- narrow screens ---------- */

@media (max-width: 820px) {
  #screen-game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "panel" "stage" "actions";
  }
  #panel { border-left: 0; border-bottom: 1px solid var(--line); padding: 8px 10px; gap: 6px; }
  .room-code { font-size: 17px; }
  #players { flex-direction: row; flex-wrap: wrap; }
  #players li { padding: 4px 8px; flex: 1 1 40%; min-width: 0; }
  #log { display: none; }
  #bag { display: none; }
  #actions { padding: 6px 8px 10px; }
  #buttons button { padding: 8px 11px; }
}
