*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Logos — mix-blend-mode: screen removes the black JPG background
   when placed on any dark UI background */
.logo, .live-logo, .control-logo {
  mix-blend-mode: screen;
}
.logo {
  display: block;
  margin: 0 auto 1.5rem;
  max-width: min(90vw, 700px);
  height: auto;
}
.live-logo {
  height: 72px;
  width: auto;
  display: block;
}
.control-title-block {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 1rem;
}
.control-logo {
  height: 52px;
  width: auto;
  display: block;
}
.control-label {
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 2px;
}


:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #f5a623;
  --text: #eaeaea;
  --text-dim: #9a9ab0;
  --green: #4caf50;
  --yellow: #f5a623;
  --radius: 10px;
}

html, body { height: 100%; font-family: 'Segoe UI', 'Hiragino Sans', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ─── Select screen ─── */
#screen-select { align-items: center; justify-content: center; }
.select-box { text-align: center; padding: 2rem; }
.select-box h1 { font-size: 3.2rem; margin-bottom: 0.8rem; color: var(--accent); letter-spacing: 2px; line-height: 1.2; }
.select-box p { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 1.1rem; }
.member-select {
  width: 240px; padding: 0.8rem 1rem; font-size: 1.2rem;
  background: var(--surface2); color: var(--text); border: 2px solid var(--surface2);
  border-radius: var(--radius); cursor: pointer; margin-bottom: 1rem;
  text-align: center; text-align-last: center;
}
.member-select:focus { outline: none; border-color: var(--accent2); }
.member-select option { background: var(--surface); color: var(--text); }
.password-input {
  width: 240px; padding: 0.7rem 1rem; font-size: 1.1rem;
  background: var(--surface2); color: var(--text);
  border: 2px solid var(--surface2); border-radius: var(--radius);
  margin-bottom: 1rem; text-align: center; letter-spacing: 2px;
  display: block; margin-left: auto; margin-right: auto;
}
.password-input:focus { outline: none; border-color: var(--accent2); }
.password-input::placeholder { color: var(--text-dim); letter-spacing: normal; }
.member-btn {
  display: block; margin: 0 auto;
  padding: 0.9rem 2.5rem; font-size: 1.2rem; font-weight: bold;
  background: var(--accent); color: white; border: 2px solid var(--accent);
  border-radius: var(--radius); cursor: pointer; transition: all 0.2s;
}
.member-btn:hover:not(:disabled) { background: #d13a51; transform: translateY(-2px); }
.member-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.select-hint { color: var(--text-dim); font-size: 0.85rem !important; margin-top: 1.5rem !important; margin-bottom: 0 !important; }

/* ─── Lobby screen ─── */
#screen-lobby { align-items: center; justify-content: center; }
.lobby-box { text-align: center; }
.lobby-box h2 { font-size: 1.8rem; margin-bottom: 1rem; }
.lobby-msg { color: var(--text-dim); font-size: 1.1rem; }
.lobby-score { margin-top: 2rem; font-size: 1.2rem; }
.lobby-score span { color: var(--accent2); font-size: 1.8rem; font-weight: bold; }

/* ─── Game screen ─── */
#screen-game { flex-direction: column; }

#game-header {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem; background: var(--surface); flex-shrink: 0;
  border-bottom: 2px solid var(--surface2);
}
#game-header .player-name { font-weight: bold; font-size: 1.1rem; min-width: 80px; }
#countdown-display {
  font-size: 2rem; font-weight: bold; min-width: 3rem; text-align: center;
  color: var(--accent2); transition: color 0.3s;
}
#countdown-display.urgent { color: var(--accent); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.5; } }

.phase-label { color: var(--text-dim); font-size: 0.9rem; flex: 1; }

#done-btn, #resume-btn {
  padding: 0.5rem 1.2rem; border: none; border-radius: var(--radius);
  font-size: 1rem; cursor: pointer; font-weight: bold; transition: all 0.2s;
}
#done-btn { background: var(--green); color: white; }
#done-btn:hover { background: #388e3c; }
#resume-btn { background: var(--accent2); color: #1a1a2e; }
#resume-btn:hover { background: #e0941f; }

#done-overlay {
  display: none; position: absolute; inset: 0;
  background: rgba(0,0,0,0.4); align-items: center; justify-content: center;
  z-index: 10; font-size: 2rem; color: var(--green);
}
#done-overlay.visible { display: flex; }

#game-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

#my-canvas-wrap { flex: 1; overflow: hidden; display: flex; position: relative; }
#my-canvas {
  width: 100%; height: 100%; background: white; cursor: crosshair;
  display: block; touch-action: none;
}
#my-canvas.locked { cursor: default; }

/* ─── Review screen (viewport-fit like Live) ─── */
#screen-review { overflow: hidden; padding: 8px; gap: 8px; }
.review-header {
  flex-shrink: 0; padding: 2px 6px;
  background: transparent; text-align: center;
}
.review-header h2 { color: var(--accent); font-size: 1.1rem; letter-spacing: 1px; }

#review-boards {
  flex: 1; display: grid;
  grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 6px; min-height: 0;
}
.review-board {
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 8px;
  overflow: hidden; min-height: 0;
  border: 2px solid transparent;
}
.review-board.me { border-color: var(--accent2); }
.review-board-name {
  flex-shrink: 0; padding: 4px 10px;
  background: var(--surface2);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.9rem; font-weight: bold;
}
.review-board-score { color: var(--accent2); font-weight: bold; }
.review-canvas {
  flex: 1; min-height: 0;
  background: white; display: block; width: 100%;
}

#review-scores {
  flex-shrink: 0; padding: 6px 10px;
  background: var(--surface); border-radius: 8px;
}
#review-scores h3 { display: none; }
#review-score-list {
  display: flex; justify-content: center;
  gap: 16px; flex-wrap: wrap;
}
.score-row {
  display: flex; align-items: center; gap: 6px;
  background: transparent; padding: 2px 6px; margin: 0;
  border-radius: 6px;
}
.score-rank { width: auto; color: var(--accent2); font-weight: bold; font-size: 0.95rem; }
.score-name { flex: 0 0 auto; font-size: 0.9rem; }
.score-pts { font-size: 0.95rem; font-weight: bold; color: var(--accent); }
.score-row.me { background: var(--surface2); }

/* ─── Shared control widgets ─── */
.btn {
  padding: 0.5rem 1.1rem; border: none; border-radius: 6px;
  font-size: 0.95rem; font-weight: bold; cursor: pointer; transition: all 0.15s;
}
.btn-start { background: var(--green); color: white; }
.btn-start:hover { background: #388e3c; }
.btn-show { background: var(--accent2); color: #1a1a2e; }
.btn-show:hover { background: #e0941f; }
.btn-reset { background: #555; color: white; }
.btn-reset:hover { background: #333; }
.btn-hide { background: #888; color: white; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #555; flex-shrink: 0; }
.status-dot.online { background: var(--green); }
.p-done-badge {
  font-size: 0.75rem; background: var(--green); color: white;
  padding: 2px 8px; border-radius: 10px; opacity: 0;
  transition: opacity 0.2s; font-weight: bold;
}
.p-done-badge.visible { opacity: 1; }

/* ─── LIVE page ─── */
body.live-body { overflow: hidden; height: 100vh; background: #0a0e27; }
#live-app {
  height: 100vh; display: flex; flex-direction: column;
  padding: 16px; gap: 12px;
}
#live-header {
  flex-shrink: 0; display: flex; align-items: center;
  justify-content: center; gap: 40px;
}
#live-title {
  font-size: 2.2rem; color: var(--text); font-weight: bold;
  letter-spacing: 2px;
}
#live-countdown {
  font-size: 5rem; font-weight: bold; color: var(--accent2);
  line-height: 1; min-width: 4ch; text-align: center;
  transition: color 0.3s;
}
#live-countdown.urgent { color: var(--accent); animation: pulse 0.5s infinite alternate; }
#live-phase-badge {
  background: var(--surface2); padding: 0.4rem 1rem; border-radius: 20px;
  color: var(--text-dim); font-size: 1rem;
}

#live-boards {
  flex: 1; display: grid;
  grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 12px; min-height: 0;
}
.live-board {
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 12px;
  overflow: hidden; min-height: 0;
  border: 3px solid transparent; transition: border-color 0.3s;
}
.live-board.done { border-color: var(--green); }
.live-board-header {
  flex-shrink: 0; padding: 6px 14px;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface2);
}
.live-board-name {
  font-size: 1.3rem; font-weight: bold; color: white;
  display: flex; align-items: center; gap: 10px;
}
.live-board-check { color: var(--green); font-size: 1.1rem; }
.live-board-score {
  font-size: 1.4rem; font-weight: bold; color: var(--accent2);
}
.live-board-canvas {
  flex: 1; background: white; min-height: 0;
  width: 100%; display: block;
}

#live-ranking {
  flex-shrink: 0; display: flex; justify-content: center;
  gap: 30px; padding: 10px 20px;
  background: var(--surface); border-radius: 10px;
}
.live-rank-item {
  display: flex; align-items: center; gap: 8px; font-size: 1.15rem;
}
.live-rank-num { font-weight: bold; color: var(--accent2); font-size: 1.3rem; min-width: 1.5rem; }
.live-rank-num.rank-1 { color: gold; }
.live-rank-num.rank-2 { color: silver; }
.live-rank-num.rank-3 { color: #cd7f32; }
.live-rank-name { color: white; }
.live-rank-score { color: var(--accent); font-weight: bold; }

/* ─── CONTROL page ─── */
body.control-body { overflow: auto; padding: 20px; }
#control-app { max-width: 960px; margin: 0 auto; }
.control-title {
  color: var(--accent); font-size: 2rem; margin-bottom: 1rem;
  letter-spacing: 1.5px;
}
.control-section {
  background: var(--surface); border-radius: 10px; padding: 1rem 1.2rem;
  margin-bottom: 12px;
}
.control-section h2 {
  color: var(--text-dim); font-size: 0.85rem; text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 0.8rem;
  border-bottom: 1px solid var(--surface2); padding-bottom: 0.4rem;
}
.control-top {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
#control-cd {
  font-size: 3rem; font-weight: bold; color: var(--accent2);
  min-width: 4rem; text-align: center;
}
#control-cd.urgent { color: var(--accent); }
#control-phase { color: var(--text-dim); font-size: 1rem; }
.control-link { margin-left: auto; color: var(--accent2); text-decoration: none; font-size: 0.9rem; }
.control-link:hover { text-decoration: underline; }
.ctrl-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl-group label { color: var(--text-dim); font-size: 0.9rem; }
.ctrl-group input[type=number] {
  width: 80px; padding: 0.5rem 0.6rem; background: var(--surface2);
  border: 1px solid #444; border-radius: 6px; color: var(--text); font-size: 1rem;
}

.pc-row {
  display: grid;
  grid-template-columns: 12px 140px 60px 1fr;
  align-items: center; gap: 10px;
  padding: 0.6rem 0; border-bottom: 1px solid var(--surface2);
}
.pc-row:last-child { border-bottom: none; }
.pc-name { font-weight: bold; font-size: 1rem; }
.pc-controls {
  display: flex; align-items: center; gap: 6px;
  justify-content: flex-end; flex-wrap: wrap;
}
.pc-current {
  min-width: 4.5rem; text-align: right;
  color: var(--text-dim); font-size: 0.9rem;
}
.pc-current b {
  font-size: 1.3rem; font-weight: bold; color: var(--accent);
  margin-right: 2px;
}
.score-input {
  width: 80px; padding: 6px 8px; background: var(--surface2);
  border: 1px solid #555; border-radius: 6px; color: var(--text);
  font-size: 1rem; text-align: center; font-weight: bold;
}
.score-input:focus { outline: none; border-color: var(--accent2); }
.score-op-btn {
  padding: 6px 14px; border: none; border-radius: 6px;
  font-size: 0.9rem; font-weight: bold; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.score-op-btn:hover { opacity: 0.85; }
.score-op-btn:active { transform: scale(0.96); }
.score-op-add { background: var(--green); color: white; }
.score-op-sub { background: #c62828; color: white; }
.score-op-set { background: var(--surface2); color: var(--text); border: 1px solid #666; }

.lb-row { display: flex; align-items: center; padding: 0.4rem 0; font-size: 1rem; }
.lb-rank { width: 2rem; color: var(--accent2); font-weight: bold; }
.lb-name { flex: 1; }
.lb-score { font-weight: bold; color: var(--accent); }

/* Control page live board previews (host-only) */
#control-boards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.control-board {
  display: flex; flex-direction: column;
  background: var(--surface2); border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent; transition: border-color 0.2s;
}
.control-board.done { border-color: var(--green); }
.control-board-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 10px; font-size: 0.9rem;
  background: var(--surface);
}
.control-board-name { font-weight: bold; }
.control-board-check { color: var(--green); font-size: 0.8rem; font-weight: bold; }
.control-board-canvas {
  width: 100%; aspect-ratio: 3/2;
  background: white; display: block;
}

/* Config editor */
.cfg-grid {
  display: grid; grid-template-columns: 150px 1fr;
  gap: 12px 16px; align-items: start;
}
.cfg-grid > label {
  padding-top: 8px; color: var(--text-dim);
  font-size: 0.9rem; font-weight: bold;
}
.cfg-grid input[type=text] {
  width: 100%; max-width: 340px;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid #444;
  border-radius: 6px;
  color: var(--text); font-size: 1rem;
}
.cfg-grid input[type=text]:focus { outline: none; border-color: var(--accent2); }
.cfg-note {
  color: var(--text-dim); font-size: 0.75rem;
  margin-top: 4px;
}
.cfg-member-row {
  display: flex; gap: 6px; margin-bottom: 6px;
  max-width: 340px;
}
.cfg-member-input {
  flex: 1;
}
.cfg-member-del {
  width: 36px; height: 36px;
  background: #c62828; color: white;
  border: none; border-radius: 6px;
  font-size: 1.1rem; font-weight: bold; cursor: pointer;
}
.cfg-member-del:hover { background: #a01a1a; }
.cfg-mini-btn {
  padding: 4px 10px; background: var(--surface2); color: var(--text);
  border: 1px solid #555; border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; margin-top: 4px;
}
.cfg-mini-btn:hover { background: #444; }
.cfg-actions {
  display: flex; gap: 10px; align-items: center;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--surface2);
}
.cfg-status { font-size: 0.9rem; }
.cfg-status.success { color: var(--green); }
.cfg-status.error { color: var(--accent); }
.cfg-status.info { color: var(--accent2); }
