:root {
  --light: #f0d9b5;
  --dark: #b58863;
  --border: #444;
  --bg: #0f172a;
  --text: #e2e8f0;
  --accent: #38bdf8;
  --danger: #ef4444;
  --dim-light: #cdd16a;
  --dim-dark: #aaa23a;
  /* JS-adjusted scale for metadata when viewport height is small */
  --meta-scale: 1;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: grid;
  place-items: center;
}

.container {
  width: min(96vw, 1600px);
  padding: 20px;
  box-sizing: border-box;
  display: grid;
  gap: 16px;
}

.title {
  margin: 0 0 4px 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}


.page-title {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(28px, 4vw, 64px);
  font-weight: 800;
  color: var(--text);
  margin: 0;
  pointer-events: none;
  z-index: 10;
  font-family: 'Georgia', serif;
}

.board-wrapper {
  display: grid;
  place-items: center;
  gap: 8px;
}

.board-shell {
  width: clamp(360px, 44vw, 720px);
  /* maintain square area for the container to avoid layout shift */
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

/* Lichess iframe should scale exactly like a board inside the shell */
.lichess-iframe {
  width: 100%;
  height: 100%;
  border: 4px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  background: var(--border);
}

.boards {
  display: grid;
  grid-template-columns: auto auto clamp(240px, 22vw, 360px);
  gap: 48px;
  align-items: start;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1; /* default; overridden dynamically */
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  grid-template-rows: repeat(var(--rows, 3), 1fr);
  border: 4px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  background: var(--border);
}

.board-8 {
  --rows: 8;
  --cols: 8;
  width: clamp(360px, 44vw, 720px);
}

.board-label {
  color: #9ca3af;
  font-size: clamp(14px, 1.6vw, 20px);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.meta {
  width: 50%;
}

.meta-card {
  width: 100%;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
  border-radius: 10px;
  padding: calc(clamp(8px, 1vw, 14px) * var(--meta-scale)) calc(clamp(10px, 1.2vw, 16px) * var(--meta-scale));
  display: grid;
  gap: calc(8px * var(--meta-scale));
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: calc(12px * var(--meta-scale));
  align-items: center;
}

.meta-label {
  color: #9ca3af;
  font-size: calc(clamp(11px, 1.1vw, 13px) * var(--meta-scale));
}

.meta-value {
  font-weight: 600;
  font-size: calc(clamp(12px, 1.2vw, 16px) * var(--meta-scale));
  text-align: right;
}
 
.meta-small {
  font-size: calc(clamp(8px, 0.8vw, 10px) * var(--meta-scale));
}

/* Style URL link in metadata to match theme */
.meta-card a {
  color: #93c5fd; /* light blue */
  text-decoration: none;
}

.meta-card a:visited {
  color: #93c5fd;
}

.meta-card a:hover {
  color: #bfdbfe; /* lighter on hover */
  text-decoration: none;
}

.next-btn {
  margin-top: 12px * var(--meta-scale);
  width: 100%;
  padding: calc(clamp(8px, 1vw, 12px) * var(--meta-scale)) calc(clamp(10px, 1.2vw, 14px) * var(--meta-scale));
  font-size: calc(clamp(10px, 1.6vw, 14px) * var(--meta-scale));
  border-radius: 8px;
  border: 1px solid #334155;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.feedback-card {
  width: 100%;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  /* Prevent children (like the Next button) from stretching vertically */
  align-items: start;
  align-content: start;
  grid-template-rows: auto auto;
}


.status-title {
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--text);
  font-size: calc(clamp(16px, 2.2vw, 24px) * var(--meta-scale));
  text-align: center;
}


.small-title {
  font-size: calc(clamp(14px, 2.0vw, 20px) * var(--meta-scale));
}

/* Keep title neutral (no red/green overrides) */

.run-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
  width: 100%;
}

.run-summary-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 100%;
}

.run-summary-box {
  width: calc(clamp(18px, 2.5vw, 28px) * var(--meta-scale));
  height: calc(clamp(18px, 2.5vw, 28px) * var(--meta-scale));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: calc(clamp(12px, 1.8vw, 18px) * var(--meta-scale));
}

.run-summary-box.correct {
  background: #34d399; /* emerald-400 */
  color: white;
}

.run-summary-box.incorrect {
  background: #f87171; /* red-400 */
  color: white;
}

.run-summary-score, .run-summary-time {
  font-size: calc(clamp(13px, 1.8vw, 16px) * var(--meta-scale));
  color: var(--text);
  font-weight: 500;
}
.run-summary-note {
  text-align: center;
  font-size: calc(clamp(12px, 1.6vw, 14px) * var(--meta-scale));
  margin-bottom: 8px;
}

/* Summary comparison table (Yours vs Average) */
.run-summary-time table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
}
.run-summary-time caption {
  caption-side: top;
  text-align: center;
  margin-bottom: 15px;
  font-size: calc(clamp(11px, 1.4vw, 14px) * var(--meta-scale));
}
.run-summary-time th,
.run-summary-time td {
  text-align: center;
  padding: calc(3px * var(--meta-scale)) calc(5px * var(--meta-scale));
  font-size: calc(clamp(11px, 1.4vw, 14px) * var(--meta-scale));
  overflow-wrap: anywhere;
}
/* Inner grid lines only (no outer border) */
.run-summary-time th + th,
.run-summary-time td + td {
  border-left: 1px solid #334155;
}
/* Ensure vertical border also between a header cell and the next data cell */
.run-summary-time tr > * + * {
  border-left: 1px solid #334155;
}
.run-summary-time tr + tr th,
.run-summary-time tr + tr td {
  border-top: 1px solid #334155;
}
/* Border between thead and first tbody row */
.run-summary-time thead + tbody tr th,
.run-summary-time thead + tbody tr td {
  border-top: 1px solid #334155;
}

.copy-link-btn {
  margin-top: 8px * var(--meta-scale);
  padding: calc(clamp(8px, 1.2vw, 12px) * var(--meta-scale)) calc(clamp(14px, 2vw, 20px) * var(--meta-scale));
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text);
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: calc(clamp(9px, 1.3vw, 12px) * var(--meta-scale));
}

.copy-link-btn:hover {
  background: #334155;
  border-color: #64748b;
  transform: translateY(-1px);
}

.copy-link-btn:active {
  transform: translateY(0);
}

.copy-link-btn.copied {
  background: #34d399;
  color: #0b1220;
  border-color: rgba(52, 211, 153, 0.35);
}

.next-btn.success {
  background: #34d399; /* emerald-400 */
  color: #0b1220;
  box-shadow: 0 6px 16px rgba(52, 211, 153, 0.25);
  border-color: rgba(52, 211, 153, 0.35);
}

.next-btn.error {
  background: #f87171; /* red-400 */
  color: #0b1220;
  box-shadow: 0 6px 16px rgba(248, 113, 113, 0.25);
  border-color: rgba(248, 113, 113, 0.35);
}

.next-btn.new-run {
  background: #60a5fa; /* blue-400 */
  color: #0b1220;
  box-shadow: 0 6px 16px rgba(96, 165, 250, 0.25);
  border-color: rgba(96, 165, 250, 0.35);
}

.next-btn:hover {
  transform: translateY(-1px);
}

.square {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  user-select: none;
}

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

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

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

.controls {
  display: grid;
  gap: 8px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: #9ca3af;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
  outline: none;
  font-size: 14px;
  transition: border-color 120ms ease;
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.15);
}

button {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #111827;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  border-color: var(--accent);
  color: #fff;
}

.error {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 13px;
}

/* Bottom menu */
.bottom-menu {
  position: fixed;
  bottom: 12px;
  left: 0;
  right: 0;
  display: flex;
  gap: 16px;
  justify-content: center;
  color: #9ca3af;
  z-index: 20;
}
.menu-btn {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #334155;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
}
.menu-btn:hover {
  border-color: #475569;
}

/* Active state for toggle-style bottom buttons */
.menu-btn[aria-pressed="true"] {
  background: #1f2937; /* slate-800 */
  color: #e5e7eb;      /* zinc-200 */
  border-color: #475569; /* slate-600 */
}

.meta-title {
  font-size: calc(clamp(12px, 2.0vw, 20px) * var(--meta-scale));
  font-weight: bold;
  text-align: center;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  display: grid;
  place-items: center;
  z-index: 30;
}
.modal-card {
  width: min(92vw, 720px);
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1f2937;
}
.modal-title {
  margin: 0;
  font-size: 18px;
}
.modal-close {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #334155;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.modal-body {
  padding: 16px;
  display: grid;
  gap: 16px;
}
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid #1f2937;
  display: flex;
  justify-content: flex-end;
}
.form-row {
  display: grid;
  gap: 8px;
}
.form-label {
  color: #9ca3af;
  font-size: 13px;
}
.form-hint {
  color: #9ca3af;
  font-size: 12px;
}
.dual-range {
  display: grid;
  gap: 8px;
}
input[type=range] {
  width: 100%;
}
.primary-btn {
  background: #34d399;
  color: #0b1220;
  border: 1px solid rgba(52, 211, 153, 0.35);
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

/* Responsive layouts */
@media (orientation: landscape) {
  .boards {
    grid-template-columns: auto auto clamp(260px, 22vw, 420px);
    gap: clamp(24px, 3vw, 40px);
    align-items: start;
    justify-content: left;
    justify-items: left;
  }
  .board,
  .board-8 {
    /* Fit within viewport height alongside title/meta */
    max-width: min(36vw, calc(100vh - 240px), 720px);
  }
  .board-shell {
    /* Keep shell constrained just like boards to avoid jumps */
    max-width: min(36vw, calc(100vh - 240px), 720px);
  }
  .meta {
    margin-top: 10%;
  }
}

@media (orientation: portrait) {
  .boards {
    grid-template-columns: 1fr;
    gap: clamp(16px, 4vw, 28px);
    align-items: center;
    justify-content: center;
    justify-items: center;
  }
  .board,
  .board-8 {
    max-width: min(92vw, calc(47vh - 140px), 560px);
  }
  .board-shell {
    max-width: min(92vw, calc(47vh - 140px), 560px);
  }
  .meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5vw;
    margin-top: 0;
    width: auto; 
    max-width: 100%;
    /*margin-left: -5vw;*/
    justify-content: center;
    align-items: start; /* prevent children from equal-height stretching */
  }
  .meta > .meta-card,
  .meta > .feedback-card {
    margin-top: 0;
    align-self: start; /* allow independent heights */
  }
  /* Hide only the table in portrait for better fit; keep the message visible */
  .run-summary-time th,
  .run-summary-time td {
    font-size: calc(clamp(7px, 1.1vw, 11px) * var(--meta-scale));
    padding: calc(1.5px * var(--meta-scale)) calc(2.5px * var(--meta-scale));
  }

  /* Bottom menu tweaks for small screens */
  .bottom-menu { gap: 8px; }
  .menu-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}


