:root {
  --ink: #232a52;
  --ink-dark: #141935;
  --paper: #fbf3e2;
  --paper-line: #e3d3ad;
  --accent: #d9622b;
  --accent-dark: #b64f1f;
  --rule: #c0392b;
  --text: #2b2620;
  --muted: #8a7f6a;
  --red: #c0392b;
  --green: #2f9e5b;
  --amber: #d99a2b;
  --gray: #9aa0a8;
  --wood: #caa15a;
  --wood-dark: #8a6a34;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Verdana, Geneva, 'Segoe UI', sans-serif;
  background:
    radial-gradient(ellipse at top, #34407a 0%, var(--ink) 45%, var(--ink-dark) 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
  font-family: inherit;
}

.screen { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 30px 16px; }
.hidden { display: none !important; }

.card-panel {
  background: var(--paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 33px, var(--paper-line) 34px
  );
  border-radius: 4px;
  border: 1px solid #d8c79a;
  padding: 30px 30px 30px 44px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  text-align: center;
  position: relative;
  margin-top: 30px;
}
.card-panel::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 26px;
  width: 2px;
  background: var(--rule);
  opacity: 0.55;
}
.card-panel-wide { max-width: 640px; }

.card-panel h1 {
  margin-top: 0;
  font-size: 26px;
  letter-spacing: 0.5px;
}
.card-panel h2 { margin-top: 0; }
.muted { color: var(--muted); font-size: 13px; }

label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 10px 0 4px; font-weight: bold; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbb98b;
  border-radius: 6px;
  font-size: 16px;
  background: #fffdf8;
  color: var(--text);
}
textarea { resize: vertical; font-size: 14px; line-height: 1.5; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 12px;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
}
button:hover:not(:disabled) { background: var(--accent-dark); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { background: #bcb29a; cursor: not-allowed; }

.btn-secondary { background: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--ink-dark); }
.btn-leave { background: transparent; color: var(--red); border: 1px solid var(--red); width: auto; padding: 8px 14px; font-size: 12px; margin: 0; }
.btn-leave:hover { background: rgba(192,57,43,0.1); }

.closed-banner {
  background: #fbe4e1;
  color: #7a1f1f;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 6px;
  margin: 10px 0;
}
.home-actions { margin-top: 18px; }
.or { margin: 14px 0 8px; color: var(--muted); font-size: 13px; }
.error { color: var(--red); font-size: 14px; min-height: 18px; margin-top: 10px; }

.link-row { display: flex; gap: 8px; margin: 10px 0 20px; }
.link-row input { flex: 1; }
.link-row button { width: auto; margin: 0; }

.players-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; justify-content: center; }
.player-chip {
  display: flex; align-items: center; gap: 6px;
  background: #fffdf8; border: 1px solid #d8c79a; border-radius: 20px;
  padding: 6px 12px 6px 6px; font-size: 13px;
}
.player-chip.disconnected { opacity: 0.5; }
.player-chip .avatar { width: 22px; height: 22px; font-size: 11px; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: bold; font-size: 13px; flex-shrink: 0;
}

.settings-block { text-align: left; margin: 18px 0; padding-top: 10px; border-top: 1px dashed #cbb98b; }
.settings-block h3 { margin: 6px 0 2px; font-size: 15px; }
.settings-row { display: flex; gap: 12px; }
.settings-field { flex: 1; }

/* --- Game screen --- */
.game-wrap { max-width: 720px; width: 100%; margin: 0 auto; padding: 16px; }

.table-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  color: #fdf6e3; margin-bottom: 12px; flex-wrap: wrap;
}
#round-indicator { font-weight: bold; font-size: 15px; }
#score-board { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; opacity: 0.9; }
#score-board .sb-item { background: rgba(255,255,255,0.1); padding: 3px 9px; border-radius: 12px; }

.letter-panel {
  display: flex; align-items: center; gap: 18px;
  background: var(--paper);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.letter-tile {
  width: 74px; height: 74px; flex-shrink: 0;
  background: linear-gradient(160deg, var(--wood), var(--wood-dark));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: bold; color: #3a2a10;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.25), 0 4px 8px rgba(0,0,0,0.3);
}
.letter-info { flex: 1; }
.timer-display { font-size: 26px; font-weight: bold; font-variant-numeric: tabular-nums; }
.timer-display.low { color: var(--red); }
.stop-banner { margin-top: 4px; font-size: 13px; font-weight: bold; color: var(--red); }
.btn-stop {
  width: auto; flex-shrink: 0; background: var(--red); animation: pulse 1.4s infinite;
}
.btn-stop:hover:not(:disabled) { background: #a5301f; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.5); } 50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); } }

.letter-history { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.letter-history .lh-tile {
  width: 26px; height: 26px; border-radius: 5px;
  background: linear-gradient(160deg, var(--wood), var(--wood-dark));
  color: #3a2a10; font-weight: bold; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2);
}
.letter-history .lh-tile.current { outline: 2px solid #fdf6e3; outline-offset: 1px; }

.answers-panel {
  background: var(--paper);
  border-radius: 10px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
@media (max-width: 480px) { .answers-panel { grid-template-columns: 1fr; } }
.answer-field label { margin: 0 0 4px; }
.answer-field input { font-size: 16px; }

.reveal-panel, .final-panel {
  background: var(--paper);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  overflow-x: auto;
}
.reveal-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.reveal-table th, .reveal-table td { padding: 8px; text-align: left; border-bottom: 1px solid #e3d3ad; white-space: nowrap; }
.reveal-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.reveal-cell { cursor: pointer; border-radius: 6px; padding: 4px 8px; display: inline-block; min-width: 60px; }
.reveal-cell.pts-10 { background: #dff3e6; color: #1a5c2e; }
.reveal-cell.pts-5 { background: #fbecd3; color: #7a5410; }
.reveal-cell.pts-0 { background: #f1f1ee; color: #888; text-decoration: line-through; }
.reveal-cell:hover { filter: brightness(0.95); }
.reveal-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.round-total { font-weight: bold; }

.final-panel h2 { text-align: center; }
.podium { list-style: none; padding: 0; margin: 0; }
.podium li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-weight: bold;
  background: #fffdf8; border: 1px solid #e3d3ad;
}
.podium li:nth-child(1) { background: #fff3cf; border-color: var(--wood); font-size: 17px; }
.podium .rank { color: var(--muted); font-weight: normal; margin-right: 8px; }
