/* ---------- Theme ---------- */
:root {
  --bg-deep: #1a120a;
  --bg-base: #221610;
  --bg-soft: #2c1d12;
  --cream: #f4ecd8;
  --cream-dim: #d4c8a8;
  --gold: #c9a86b;
  --gold-bright: #e6c98c;
  --claret: #7a1f2b;
  --moss: #3d6e5e;
  --ink: #1a0d05;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(ellipse at top, #2a1d12 0%, var(--bg-deep) 50%, #0e0805 100%);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100vh;
  width: 100vw;
  overflow: auto;
}

button {
  font-family: var(--sans);
  cursor: pointer;
  border: none;
  outline: none;
}

.screen {
  min-height: 100vh;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 16px;
}
.topbar > * { display: flex; align-items: center; gap: 12px; }

.lesson-pill, .profile-pill {
  background: rgba(201, 168, 107, 0.12);
  border: 1px solid rgba(201, 168, 107, 0.3);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 13px;
  color: var(--cream-dim);
  letter-spacing: 0.02em;
}

.lesson-nav { gap: 4px; }
.lesson-nav button { font-size: 18px; padding: 4px 12px; }

.ghost-button {
  background: transparent;
  color: var(--cream-dim);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all 120ms ease;
}
.ghost-button:hover:not(:disabled) {
  background: rgba(244, 236, 216, 0.08);
  color: var(--cream);
}
.ghost-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.primary-button {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
  padding: 10px 22px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(201, 168, 107, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 120ms ease;
}
.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(201, 168, 107, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.primary-button:active { transform: translateY(0); }
.primary-button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ---------- Profile screen ---------- */
.profiles-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.title-art {
  margin: 32px 0 56px;
  user-select: none;
}
.title-main {
  font-family: var(--serif);
  font-size: clamp(48px, 7vw, 88px);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 50%, #8a6a3a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 2px 12px rgba(201, 168, 107, 0.15);
}
.title-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--cream-dim);
  opacity: 0.7;
  margin-top: 8px;
}

.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 200px));
  gap: 20px;
  justify-content: center;
  max-width: 900px;
}

.profile-card {
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.04), rgba(244, 236, 216, 0.02));
  border: 1px solid rgba(201, 168, 107, 0.2);
  border-radius: 16px;
  padding: 28px 20px 20px;
  cursor: pointer;
  transition: all 180ms ease;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 200px;
}
.profile-card:hover {
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.08), rgba(244, 236, 216, 0.04));
  border-color: rgba(201, 168, 107, 0.5);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  color: var(--cream);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 -4px 12px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.3);
}
.avatar.small {
  width: 32px;
  height: 32px;
  font-size: 16px;
}
.profile-name {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
}
.profile-stats {
  font-size: 12px;
  color: var(--cream-dim);
  opacity: 0.75;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.delete-profile {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  color: var(--cream-dim);
  font-size: 18px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 120ms ease;
}
.profile-card:hover .delete-profile { opacity: 0.5; }
.delete-profile:hover { background: rgba(122, 31, 43, 0.4); opacity: 1; }

.add-card {
  border-style: dashed;
  border-color: rgba(201, 168, 107, 0.3);
  background: transparent;
}
.add-plus {
  font-size: 56px;
  color: var(--gold);
  opacity: 0.6;
  font-weight: 200;
  line-height: 1;
}

.new-profile-form {
  margin-top: 32px;
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.06), rgba(244, 236, 216, 0.03));
  border: 1px solid rgba(201, 168, 107, 0.3);
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
}
.new-profile-form input {
  width: 100%;
  background: rgba(26, 13, 5, 0.5);
  border: 1px solid rgba(201, 168, 107, 0.3);
  color: var(--cream);
  padding: 12px 14px;
  border-radius: 8px;
  font-family: var(--serif);
  font-size: 18px;
  outline: none;
  transition: border-color 120ms ease;
}
.new-profile-form input:focus { border-color: var(--gold); }

.color-row {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
  justify-content: center;
}
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: transform 120ms ease;
  box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.3);
}
.color-swatch:hover { transform: scale(1.1); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ---------- Home screen ---------- */
.home-screen { padding: 24px 32px; }
.home-content {
  margin-top: 60px;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.home-content h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 36px;
  margin-bottom: 40px;
  color: var(--cream);
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 320px));
  gap: 24px;
  margin-bottom: 32px;
}
.mode-card {
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.04), rgba(244, 236, 216, 0.02));
  border: 1px solid rgba(201, 168, 107, 0.2);
  border-radius: 16px;
  padding: 32px 24px;
  cursor: pointer;
  transition: all 200ms ease;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.mode-card:hover {
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.08), rgba(244, 236, 216, 0.04));
  border-color: rgba(201, 168, 107, 0.5);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}
.mode-icon { font-size: 44px; margin-bottom: 12px; }
.mode-card h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  margin: 0 0 8px;
}
.mode-card p {
  color: var(--cream-dim);
  margin: 0 0 16px;
  font-size: 14px;
}
.progress-bar {
  height: 4px;
  background: rgba(201, 168, 107, 0.15);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 16px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 99px;
  transition: width 300ms ease;
}

.difficulty-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}
.diff-btn {
  background: rgba(244, 236, 216, 0.08);
  color: var(--cream-dim);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  text-transform: capitalize;
  transition: all 120ms ease;
}
.diff-btn.active {
  background: var(--gold);
  color: var(--ink);
}
.diff-btn:hover:not(.active) { background: rgba(201, 168, 107, 0.2); color: var(--cream); }

.record {
  font-family: var(--serif);
  font-size: 16px;
  color: var(--cream-dim);
  font-style: italic;
}

/* ---------- Tutorial / Game layout ---------- */
.tutorial-layout, .game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: stretch;
  min-height: 0;
}

.board-wrap {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.4));
  border-radius: 18px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  min-height: 0;
}
.bg-board {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 120px);
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.5));
}

.side-panel {
  background: linear-gradient(180deg, rgba(244, 236, 216, 0.04), rgba(244, 236, 216, 0.02));
  border: 1px solid rgba(201, 168, 107, 0.2);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 96px);
}
.side-panel h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  margin: 0;
  color: var(--gold-bright);
}

.narration {
  font-size: 15px;
  line-height: 1.7;
  color: var(--cream);
}
.narration p { margin: 0 0 12px; }
.narration ul { margin: 0 0 12px; padding-left: 20px; }
.narration li { margin-bottom: 4px; }
.narration strong { color: var(--gold-bright); font-weight: 600; }
.narration em { color: var(--cream-dim); }

.dice-row {
  display: flex;
  justify-content: center;
  padding: 12px 0;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
}
.dice-placeholder { height: 80px; }

.message {
  background: rgba(201, 168, 107, 0.12);
  border-left: 3px solid var(--gold);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--cream);
}

.hint {
  font-size: 13px;
  color: var(--cream-dim);
  font-style: italic;
  padding: 4px 0;
}

.coach-hint {
  background: linear-gradient(180deg, rgba(61, 110, 94, 0.18), rgba(61, 110, 94, 0.08));
  border: 1px solid rgba(61, 110, 94, 0.5);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.coach-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.coach-icon { font-size: 14px; }
.coach-moves {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--cream);
  letter-spacing: 0.04em;
}
.coach-reason {
  font-size: 13px;
  line-height: 1.55;
  color: var(--cream-dim);
}
.coach-play {
  align-self: flex-start;
  background: rgba(201, 168, 107, 0.18);
  color: var(--cream);
  border: 1px solid rgba(201, 168, 107, 0.4);
  margin-top: 2px;
}
.coach-play:hover { background: rgba(201, 168, 107, 0.32); }

.coach-review {
  background: linear-gradient(180deg, rgba(122, 31, 43, 0.12), rgba(122, 31, 43, 0.04));
  border: 1px solid rgba(201, 168, 107, 0.3);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.coach-review-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.coach-review-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--cream-dim);
  margin: 0;
}
.coach-api-input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(201, 168, 107, 0.3);
  color: var(--cream);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
}
.coach-api-input:focus { border-color: var(--gold); }
.coach-review-text {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--cream);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.coach-review-error {
  font-size: 13px;
  color: #e0a0a0;
  background: rgba(122, 31, 43, 0.2);
  border-left: 3px solid #c44;
  padding: 8px 12px;
  border-radius: 6px;
  word-wrap: break-word;
}
.coach-spinner {
  color: var(--gold);
  animation: pulse 1.4s infinite ease-in-out;
}
.caret {
  display: inline-block;
  color: var(--gold);
  animation: pulse 1s infinite ease-in-out;
}

.thinking {
  font-size: 28px;
  color: var(--gold);
  text-align: center;
  letter-spacing: 8px;
  animation: pulse 1.4s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.rules-recap {
  margin-top: auto;
  font-size: 12px;
  color: var(--cream-dim);
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 10px 14px;
}
.rules-recap summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--cream);
}
.rules-recap ul { margin: 8px 0 0; padding-left: 18px; }
.rules-recap li { margin-bottom: 4px; }

/* ---------- Game info bar ---------- */
.game-info {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--cream-dim);
}
.player-pip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 14px;
  border-radius: 99px;
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.3);
}
.dot.light { background: radial-gradient(circle at 35% 30%, #fff8e7, #9a8554); }
.dot.dark  { background: radial-gradient(circle at 35% 30%, #a83947, #3a0c14); }
.vs {
  font-family: var(--serif);
  font-style: italic;
  opacity: 0.6;
}

/* ---------- SVG board interactions ---------- */
.bg-board { user-select: none; cursor: default; }
.bg-board polygon, .bg-board g { transition: opacity 120ms ease; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .tutorial-layout, .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .side-panel { max-height: none; }
  .bg-board { max-height: 60vh; }
}
@media (max-width: 600px) {
  .screen { padding: 12px; }
  .home-content h1 { font-size: 26px; }
  .mode-cards { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
