:root {
  color-scheme: dark;
  --bg: #12100d;
  --bg-panel: #1c1812;
  --bg-panel-2: #221c14;
  --border: #3a3120;
  --gold: #c9a856;
  --gold-bright: #e8c96f;
  --text: #e8e2d4;
  --text-dim: #a99f8a;
  --danger: #b5453c;
  --ok: #5a8f5a;
  --p1: #6fa8dc;
  --p2: #d97b6c;
  --radius: 8px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #1a160f 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
  margin: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1e1a12, #171310);
  position: sticky;
  top: 0;
  z-index: 5;
}

.app-header h1 {
  font-size: 1.4rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.conn-status {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.conn-online {
  color: #bfe3bf;
  border-color: var(--ok);
}

.conn-offline {
  color: #e3bcbc;
  border-color: var(--danger);
}

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

.link-btn:hover {
  color: var(--gold-bright);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Player panels */
.player-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.player-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.player-panel.slot-p1 {
  border-top: 3px solid var(--p1);
}

.player-panel.slot-p2 {
  border-top: 3px solid var(--p2);
}

.player-panel.is-me {
  box-shadow: 0 0 0 1px var(--gold) inset;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.player-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.1rem 0.2rem;
  width: 100%;
}

.player-name-input:not([readonly]) {
  border-bottom-color: var(--border);
  cursor: text;
}

.player-name-input[readonly] {
  cursor: default;
}

.me-badge {
  font-size: 0.7rem;
  color: var(--bg);
  background: var(--gold);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.timer-display {
  font-variant-numeric: tabular-nums;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0.25rem 0 0.6rem;
}

.timer-display.running {
  color: var(--gold-bright);
}

.timer-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.timer-controls button {
  flex: 1;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.timer-controls button:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.timer-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.progress-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-panel-2);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
}

.slot-p1 .progress-fill {
  background: linear-gradient(90deg, #3f6a94, var(--p1));
}

.slot-p2 .progress-fill {
  background: linear-gradient(90deg, #8a4638, var(--p2));
}

/* Board / table */
.board {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

#filter-input {
  flex: 1;
  min-width: 180px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  color: var(--text);
}

.sort-toggle {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.col-idx {
  width: 2.5rem;
  text-align: right;
}

.col-player {
  width: 9rem;
  text-align: center;
}

tbody tr {
  border-bottom: 1px solid #2a2418;
}

tbody tr:hover {
  background: rgba(201, 168, 86, 0.06);
}

tbody td {
  padding: 0.45rem 0.5rem;
  vertical-align: top;
}

.idx-cell {
  color: var(--text-dim);
  text-align: right;
}

.title-cell .title {
  font-weight: 600;
}

.title-cell .desc {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.1rem;
}

.check-cell {
  text-align: center;
}

.check-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  color: var(--text-dim);
  min-width: 6.5rem;
}

.check-btn:disabled {
  cursor: default;
}

.check-btn .box {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: inline-block;
}

.check-btn.done .box {
  background: var(--ok);
  border-color: var(--ok);
}

.check-btn.done {
  color: var(--text);
}

.check-btn:not(:disabled):hover {
  border-color: var(--gold);
}

.check-time {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Log panel */
.log-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.log-panel h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.log-list li {
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid #2a2418;
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.log-list .log-slot {
  font-weight: 700;
  min-width: 5.5rem;
}

.log-list .slot-p1 {
  color: var(--p1);
}

.log-list .slot-p2 {
  color: var(--p2);
}

.log-list .log-time {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-left: auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.log-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay.hidden {
  display: none;
}

.role-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  max-width: 360px;
}

.role-card h1 {
  margin-bottom: 0.5rem;
}

.role-buttons {
  display: flex;
  gap: 1rem;
  margin: 1.25rem 0 0.75rem;
}

.role-btn {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--gold);
  background: var(--bg-panel-2);
  color: var(--gold-bright);
  cursor: pointer;
  font-size: 1rem;
}

.role-btn:hover {
  background: var(--gold);
  color: var(--bg);
}

.hint {
  color: var(--text-dim);
  font-size: 0.8rem;
}

@media (max-width: 720px) {
  .player-panels {
    grid-template-columns: 1fr;
  }

  .timer-display {
    font-size: 2rem;
  }
}
