:root {
  --bg: #f3efe7;
  --panel: #ffffff;
  --light-sq: #ede0c8;
  --dark-sq: #8b6f47;
  --accent: #d97706;
  --text: #1f1b14;
  --font: 'Georgia', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: background 0.6s ease, color 0.6s ease;
}

main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

[hidden] { display: none !important; }

/* ---------- Prompt screen ---------- */
.prompt-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 3rem 2.5rem;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.08);
}

.prompt-card h1 {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0 0 2rem;
  opacity: 0.7;
  font-style: italic;
}

#whimsy-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#whimsy-form label {
  text-align: left;
  font-weight: 600;
  font-size: 0.95rem;
}

#whimsy-input {
  padding: 0.85rem 1rem;
  font-size: 1rem;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

#whimsy-input:focus {
  outline: none;
  border-color: var(--accent);
}

#whimsy-form button {
  padding: 0.85rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, filter 0.2s;
}

#whimsy-form button:hover { filter: brightness(1.1); }
#whimsy-form button:active { transform: scale(0.98); }

.hint {
  margin-top: 1.5rem;
  opacity: 0.6;
  font-size: 0.9rem;
}

/* ---------- Opponent fieldset ---------- */
.opponent-fieldset {
  border: 1.5px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  padding: 0.75rem 1rem 1rem;
  text-align: left;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.opponent-fieldset legend {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.65;
  padding: 0 0.4rem;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.radio-row input[type="radio"] {
  accent-color: var(--accent);
}

.ai-options {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.25rem;
  padding-top: 0.6rem;
  border-top: 1px dashed rgba(0,0,0,0.1);
}

.ai-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.ai-row-label {
  font-size: 0.85rem;
  opacity: 0.7;
  font-weight: 600;
  min-width: 5rem;
}

.pill {
  cursor: pointer;
  font-size: 0.85rem;
  position: relative;
}

.pill input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pill span {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.05);
  border: 1.5px solid transparent;
  transition: all 0.15s;
}

.pill input[type="radio"]:checked + span {
  background: var(--accent);
  color: white;
}

.pill:hover input[type="radio"]:not(:checked) + span {
  border-color: var(--accent);
}

/* ---------- Loading screen ---------- */
.loading-card {
  text-align: center;
  max-width: 480px;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(0,0,0,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1.5rem;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-detail { opacity: 0.7; }

/* ---------- Share link / waiting screen ---------- */
.share-link-wrap {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

.share-link-wrap input {
  flex: 1;
  padding: 0.7rem 0.85rem;
  font-size: 0.95rem;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  min-width: 0;
}

.share-link-wrap button {
  padding: 0.7rem 1.1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s;
}

.share-link-wrap button:hover { filter: brightness(1.1); }

.link-button {
  background: none;
  border: none;
  color: var(--text);
  opacity: 0.55;
  text-decoration: underline;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  margin-top: 1.25rem;
  padding: 0.3rem;
}

.link-button:hover { opacity: 0.9; }

.share-status-connected { color: var(--accent); font-weight: 700; }

/* ---------- Game screen ---------- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  gap: 1rem;
}

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

/* Whimsification filter toggle */
.filter-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.filter-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.filter-toggle-track {
  display: inline-block;
  width: 36px;
  height: 20px;
  background: rgba(0,0,0,0.15);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
}

.filter-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.filter-toggle input:checked + .filter-toggle-track {
  background: var(--accent);
}

.filter-toggle input:checked + .filter-toggle-track .filter-toggle-knob {
  transform: translateX(16px);
}

.filter-toggle-label {
  opacity: 0.85;
}

.game-header h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.01em;
}

#new-whimsy {
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: background 0.2s;
}

#new-whimsy:hover {
  background: var(--accent);
  color: white;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 2rem;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem 2rem;
  align-items: start;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  max-width: 640px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  user-select: none;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.square.light { background: var(--light-sq); }
.square.dark  { background: var(--dark-sq); }

/* Colored halo behind each piece, hardcoded so it's visible regardless of theme art. */
.square.has-piece::before {
  content: '';
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  z-index: 0;
  pointer-events: none;
}
.square.piece-white::before {
  background: radial-gradient(circle, rgba(255, 248, 220, 0.55) 0%, rgba(255, 248, 220, 0.15) 55%, transparent 75%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 245, 200, 0.5);
}
.square.piece-black::before {
  background: radial-gradient(circle, rgba(30, 25, 45, 0.55) 0%, rgba(30, 25, 45, 0.15) 55%, transparent 75%);
  box-shadow: inset 0 0 0 1.5px rgba(40, 35, 55, 0.6);
}

.square img,
.square .cast-emoji,
.square .standard-piece {
  position: relative;
  z-index: 1;
}

.square img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}

/* Standard chess pieces (when Whimsy filter is OFF). */
.square .standard-piece {
  font-size: clamp(2.5rem, 7vw, 4rem);
  line-height: 1;
  font-family: 'Segoe UI Symbol', 'Apple Symbols', system-ui, sans-serif;
  user-select: none;
}
.square .standard-piece.white {
  color: #f8f4e9;
  text-shadow:
    -1px -1px 0 #1a1a1a, 1px -1px 0 #1a1a1a,
    -1px  1px 0 #1a1a1a, 1px  1px 0 #1a1a1a,
    0 2px 4px rgba(0,0,0,0.3);
}
.square .standard-piece.black {
  color: #1a1a1a;
  text-shadow:
    -1px -1px 0 #f8f4e9, 1px -1px 0 #f8f4e9,
    -1px  1px 0 #f8f4e9, 1px  1px 0 #f8f4e9,
    0 2px 4px rgba(0,0,0,0.3);
}

.square.selected {
  box-shadow: inset 0 0 0 4px var(--accent);
}

.square.legal::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.45;
  pointer-events: none;
  z-index: 2;
}

.square.legal:has(img)::after,
.square.legal.has-piece::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 4px solid var(--accent);
  opacity: 0.7;
}

/* Distinct soft-overlay highlight for the last move (different from selection). */
.square.move-from {
  background-image: linear-gradient(rgba(255, 220, 120, 0.45), rgba(255, 220, 120, 0.45));
}
.square.move-to {
  background-image: linear-gradient(rgba(255, 200, 80, 0.55), rgba(255, 200, 80, 0.55));
}

/* The traveling piece during a move animation. */
.square .moving {
  transition: transform 0.32s cubic-bezier(0.4, 0.0, 0.2, 1);
  will-change: transform;
  z-index: 20;
}

/* ---------- Side panel ---------- */
.side-panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel-section .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.turn {
  font-size: 1.25rem;
  font-weight: 700;
}

/* ---------- Captures + material score ---------- */
.captures-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.captures-side-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.5;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.captures-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 28px;
  padding: 4px;
  background: rgba(0,0,0,0.04);
  border-radius: 6px;
}

.captures-tray .cap-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.captures-tray .cap-emoji,
.captures-tray .cap-glyph {
  font-size: 1.1rem;
  line-height: 1;
  display: inline-block;
  width: 22px;
  text-align: center;
}

.captures-tray .cap-glyph.white { color: #f8f4e9; text-shadow: 0 0 1px #222, 0 0 2px #222; }
.captures-tray .cap-glyph.black { color: #1a1a1a; }

.material-score {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  opacity: 0.75;
  min-height: 1.2em;
}

.material-score .leader {
  color: var(--accent);
}

.act-name {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.intro-section p,
.flavor-section p {
  margin: 0;
  line-height: 1.5;
  font-style: italic;
}

.fade-in {
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.flavor-section p {
  min-height: 3em;
  font-size: 1.05rem;
  font-style: normal;
}

.cast summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0.7;
  padding: 0.4rem 0;
}

.cast-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}

.cast-column {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.cast-side-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  font-weight: 700;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(0,0,0,0.12);
  margin-bottom: 0.15rem;
}

.cast-piece {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.85rem;
  min-width: 0;
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1.25;
}

.cast-piece:hover {
  background: rgba(0,0,0,0.05);
}

.cast-piece .cast-name {
  flex: 1;
  word-wrap: break-word;
  hyphens: auto;
  padding-top: 0.35rem;
}

.cast-piece img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.cast-piece .cast-emoji {
  font-size: 1.5rem;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1.5;
}

/* ---------- Piece detail modal ---------- */
.piece-modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 420px;
  width: calc(100% - 2rem);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font);
  box-shadow: 0 30px 80px rgba(0,0,0,0.3);
}

.piece-modal::backdrop {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}

.piece-modal[open] {
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content {
  padding: 2rem 2rem 1.75rem;
  position: relative;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  opacity: 0.5;
  font-family: inherit;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  transition: opacity 0.15s, background 0.15s;
}

.modal-close:hover {
  opacity: 1;
  background: rgba(0,0,0,0.06);
}

.modal-image {
  width: 140px;
  height: 140px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));
}

.modal-image .cast-emoji {
  font-size: 5rem;
  line-height: 1;
}

.modal-name {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.modal-meta {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.6;
  margin-bottom: 1rem;
  font-weight: 700;
}

.modal-personality {
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0 0 1.25rem;
  opacity: 0.9;
}

.modal-quips {
  text-align: left;
  border-top: 1px solid rgba(0,0,0,0.08);
  padding-top: 1rem;
}

.modal-quips .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.modal-quips ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-quips li {
  font-size: 0.95rem;
  font-style: italic;
  line-height: 1.4;
  padding-left: 0.85rem;
  border-left: 2px solid var(--accent);
  opacity: 0.85;
}
