/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0e17;
  --surface: #1c1b29;
  --surface2: #252438;
  --accent: #4dabf7;
  --accent2: #74c0fc;
  --success: #2ecc71;
  --warning: #f39c12;
  --text: #fffffe;
  --text-muted: #a7a9be;
  --border: #2e2d40;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ─── Screens ────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; padding: 20px; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
}
.join-card { max-width: 560px; }
.lobby-card { max-width: 500px; }
.result-card { max-width: 900px; }

/* ─── Back to portal ────────────────────────────────────────── */
.back-to-portal {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
}
.back-to-portal:hover { color: var(--text); text-decoration: underline; }

/* ─── Typography ─────────────────────────────────────────────── */
.game-title {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), #9775fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; font-size: 0.95rem; }
h2 { font-size: 1.4rem; margin-bottom: 16px; }
h3 { font-size: 1.1rem; margin-bottom: 12px; color: var(--text-muted); }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
input[type="text"], input[type="number"], select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { border-color: var(--accent); }

.round-select-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.round-select-btn {
  flex: 1;
  min-width: 44px;
  padding: 10px 0;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.round-select-btn:hover { border-color: var(--text-muted); }
.round-select-btn.selected {
  border-color: var(--accent);
  background: rgba(77, 171, 247, 0.18);
  color: var(--accent2);
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent2); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:not(:disabled):hover { filter: brightness(1.1); }
.btn-full { width: 100%; margin-top: 8px; }
.btn-small { padding: 4px 10px; font-size: 0.8rem; background: var(--surface2); color: var(--text-muted); }

/* ─── Error / Hint ───────────────────────────────────────────── */
.error-msg { color: var(--accent); font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; text-align: center; }
.hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 12px; text-align: center; }

/* ─── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Icon selector ──────────────────────────────────────────── */
.icon-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
}
.icon-btn {
  width: 100px;
  height: 100px;
  padding: 4px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--text-muted); transform: scale(1.08); }
.icon-btn.selected {
  border-color: var(--accent);
  background: rgba(77, 171, 247, 0.15);
  transform: scale(1.12);
}
.icon-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}
.icon-missing { background: var(--surface2); }

/* ─── Room ID badge ──────────────────────────────────────────── */
.room-id-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.room-id-label { color: var(--text-muted); font-size: 0.9rem; }
.room-id-badge {
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 10px;
  color: var(--warning);
  letter-spacing: 1px;
}
.player-count { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 16px; }

/* ─── Player list ────────────────────────────────────────────── */
.player-list { list-style: none; margin-bottom: 20px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  margin-bottom: 6px;
}
.player-icon-sm {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid;
  overflow: hidden;
  flex-shrink: 0;
  padding: 2px;
  background: var(--surface2);
}
.player-name { font-weight: 600; }
.host-badge {
  margin-left: auto;
  font-size: 0.75rem;
  background: var(--warning);
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
}
.me-badge {
  font-size: 0.75rem;
  background: var(--surface);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 4px;
}
.waiting-text { color: var(--text-muted); text-align: center; padding: 12px 0; }

/* ─── Round badge ────────────────────────────────────────────── */
.round-badge {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ─── Drawing screen ─────────────────────────────────────────── */
.drawing-layout {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawing-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.turn-indicator {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.turn-indicator.my-turn {
  color: var(--success);
  animation: pulse-text 1.5s ease-in-out infinite;
}
@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ─── お絵描きメイン行（PCでは前の絵とキャンバスを横並び） ─────── */
.drawing-main-row {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

/* ─── 前の人の絵（自分の番のときだけ表示・キャプションは非公開） ─── */
.prev-entry-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex: 0 0 42%;
  min-width: 0;
}
.prev-entry-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}
.prev-entry-img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  min-height: 200px;
}
.prev-entry-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.prev-entry-author {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #fff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

.wait-panel {
  padding: 60px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.wait-panel .wait-icon { font-size: 2.4rem; margin-bottom: 12px; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.dot-anim { animation: blink 1.2s infinite; }

.wait-prev-entry {
  max-width: 320px;
  margin: 20px auto 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.wait-prev-entry .prev-entry-img-wrap { min-height: 160px; }

.caption-row {
  display: flex;
  gap: 8px;
}
.caption-row input { flex: 1; }

.canvas-tools {
  display: flex;
  justify-content: flex-end;
}

.drawing-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.turn-order {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.turn-dot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.turn-dot {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 2px solid transparent;
  overflow: hidden;
  padding: 3px;
  background: var(--surface2);
  transition: transform 0.2s, box-shadow 0.2s;
}
.turn-dot.active {
  transform: scale(1.25);
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}
.turn-dot.done { opacity: 0.3; }
.turn-name { font-size: 0.65rem; color: var(--text-muted); max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Result / Gallery screen（縦一列＋矢印でチェーン表示） ───── */
.gallery-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 420px;
  margin: 0 auto;
}
.gallery-card {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.gallery-round-badge {
  align-self: flex-start;
  margin: 10px 12px 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
}
.gallery-img-wrap {
  background: #fff;
  aspect-ratio: 7 / 5;
}
.gallery-img-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.gallery-caption {
  padding: 10px 12px;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}
.gallery-author {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.gallery-author .player-icon-sm { width: 26px; height: 26px; border-radius: 6px; }

.gallery-arrow {
  font-size: 1.6rem;
  color: var(--accent);
  line-height: 1;
  padding: 6px 0;
}

.result-buttons { text-align: center; margin-top: 24px; }
.result-buttons .btn { margin: 6px; }

/* ─── Rules accordion ───────────────────────────────────────── */
.rules-details {
  margin-top: 16px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rules-summary {
  list-style: none;
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
}
.rules-summary::-webkit-details-marker { display: none; }
.rules-summary:hover { color: var(--text); }
.rules-details[open] .rules-summary { border-bottom: 1px solid var(--border); }
.rules-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface2);
}
.rules-heading {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.rules-body ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rules-body li {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding-left: 12px;
  position: relative;
}
.rules-body li::before {
  content: '・';
  position: absolute;
  left: 0;
}
.rules-body strong { color: var(--text); }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .card { padding: 20px; }
  .drawing-header { flex-direction: column; align-items: stretch; }
  .drawing-main-row { flex-direction: column; }
  .prev-entry-area { flex: none; }
  .prev-entry-img-wrap { min-height: 140px; }
  .gallery-chain { max-width: 100%; }
}
