/* ════════════════════════════════════════════════
   DESIGN TOKENS
   Edit this section to restyle the entire app.
   ════════════════════════════════════════════════ */
:root {
  /* ── Typography ── */
  --font-main:     'Helvetica Neue', 'Arial', sans-serif;
  --font-mono:     'SF Mono', 'Fira Code', monospace;
  --font-jp:       'Hiragino Kaku Gothic Pro', 'MS Gothic', 'Noto Sans JP', sans-serif;

  --text-xs:   0.70rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.375rem;
  --text-xl:   2rem;
  --text-xxl:  3.5rem;

  /* ── Palette (app chrome — not the swatches) ── */
  --color-bg:          #f6f5f0;   /* warm off-white, paper-like */
  --color-surface:     #ffffff;
  --color-border:      #ddddd8;
  --color-text:        #1a1a1a;
  --color-text-muted:  #888884;
  --color-accent:      #c0392b;   /* Japanese vermilion */
  --color-accent-dim:  rgba(192,57,43,0.12);

  /* ── Spacing ── */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* ── Misc ── */
  --radius:      2px;
  --header-h:    3rem;
  --ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --transition:  0.18s var(--ease);

  /* ── Swatch label ── */
  --label-bg:    rgba(255,255,255,0.82);
  --label-blur:  4px;
}

/* ════════════════════════════════════════════════
   RESET & BASE
   ════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--text-base);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

a           { color: var(--color-accent); text-decoration: none; }
a:hover     { text-decoration: underline; }
button      { font-family: inherit; cursor: pointer; }
fieldset    { border: none; }

/* ════════════════════════════════════════════════
   SCREEN SYSTEM
   Each screen is hidden by default; .active shows it.
   ════════════════════════════════════════════════ */
.screen         { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active  { display: flex; }

/* ════════════════════════════════════════════════
   WELCOME SCREEN
   ════════════════════════════════════════════════ */
.welcome-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-16) var(--sp-6);
  gap: var(--sp-8);
}

/* Japanese-style title */
.app-title {
  font-family: var(--font-jp);
  font-size: var(--text-xxl);
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--color-text);
  line-height: 1.1;
}

.app-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: var(--sp-1);
}

/* ── Setup form ── */
.setup-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  width: 100%;
  max-width: 460px;
}

.form-group {
  border: 1px solid var(--color-border);
  padding: var(--sp-4) var(--sp-6) var(--sp-6);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.form-group legend {
  font-size: var(--text-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0 var(--sp-2);
}

.radio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.radio-opt {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--color-bg);
  transition: border-color var(--transition), background var(--transition);
  user-select: none;
}

.radio-opt:hover                  { background: var(--color-surface); border-color: var(--color-text-muted); }
.radio-opt:has(input:checked)     { border-color: var(--color-text);  background: var(--color-surface); }

.radio-opt input[type="radio"] {
  appearance: none;
  width: 1em;
  height: 1em;
  border: 1.5px solid var(--color-text-muted);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.15em;
  transition: background var(--transition), border-color var(--transition);
}
.radio-opt input[type="radio"]:checked {
  background: var(--color-text);
  border-color: var(--color-text);
}

.opt-label {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.opt-name  { font-size: var(--text-sm);  font-weight: 500; }
.opt-desc  { font-size: var(--text-xs);  color: var(--color-text-muted); margin-top: 1px; }

.check-opt {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--color-bg);
  transition: border-color var(--transition), background var(--transition);
  user-select: none;
}
.check-opt:hover                     { background: var(--color-surface); border-color: var(--color-text-muted); }
.check-opt:has(input:checked)        { border-color: var(--color-text);  background: var(--color-surface); }

.check-opt input[type="checkbox"] {
  appearance: none;
  width: 1em;
  height: 1em;
  border: 1.5px solid var(--color-text-muted);
  border-radius: var(--radius);
  flex-shrink: 0;
  margin-top: 0.15em;
  transition: background var(--transition), border-color var(--transition);
}
.check-opt input[type="checkbox"]:checked {
  background: var(--color-text);
  border-color: var(--color-text);
}

.form-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

#est-comparisons {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
}

/* ── Resume prompt ── */
.resume-prompt {
  width: 100%;
  max-width: 460px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-6);
  text-align: center;
}

.resume-prompt p { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--sp-4); }

.resume-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
}

/* ════════════════════════════════════════════════
   COMPARING SCREEN
   ════════════════════════════════════════════════ */
#screen-comparing {
  background: #111; /* dark surround keeps colours vivid */
}

.compare-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  flex-shrink: 0;
  gap: var(--sp-4);
  z-index: 10;
}

.compare-prompt {
  text-align: center;
  font-size: var(--text-xs);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  padding: var(--sp-2) 0;
  flex-shrink: 0;
  background: rgba(0,0,0,0.6);
}

.progress-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 120px;
}

.progress-label {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.05em;
}

.progress-track {
  width: 120px;
  height: 2px;
  background: rgba(255,255,255,0.15);
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 1px;
  transition: width 0.4s var(--ease);
}

/* ── Swatches ── */
.swatches {
  flex: 1;
  display: flex;
  flex-direction: row;      /* landscape: side by side */
  min-height: 0;
}

/* Portrait / narrow → stack vertically */
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  .swatches { flex-direction: column; }
}

.swatch {
  flex: 1;
  border: none;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--sp-8);
  transition: filter var(--transition);
  outline: none;
  min-height: 40dvh;
  cursor: pointer;
}

/* Tap / keyboard focus */
.swatch:focus-visible {
  outline: 3px solid rgba(255,255,255,0.8);
  outline-offset: -3px;
}

/* Chosen flash animation */
.swatch.chosen { animation: chosen-flash 0.22s var(--ease); }

@keyframes chosen-flash {
  0%   { filter: brightness(1);   }
  40%  { filter: brightness(1.35);}
  100% { filter: brightness(1);   }
}

/* Thin divider between the two swatches */
.swatch + .swatch::before {
  content: '';
  position: absolute;
  /* vertical divider in landscape */
  top: 0; bottom: 0; left: 0;
  width: 2px;
  background: rgba(0,0,0,0.35);
}
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  .swatch + .swatch::before {
    top: 0; left: 0; right: 0; bottom: auto;
    width: auto; height: 2px;
  }
}

.swatch-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: var(--sp-1) var(--sp-3);
  border-radius: 1px;
  border: 1px solid currentColor;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  /* color is set dynamically for contrast */
}

.swatch-label--hidden {
  display: none;
}

/* Show label on hover / focus */
.swatch:hover .swatch-label,
.swatch:focus-visible .swatch-label { opacity: 0.8; }

/* Always visible on touch devices */
@media (hover: none) { .swatch-label { opacity: 0.75; } }

/* ── Settings panel ── */
.settings-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.88);
  color: rgba(255,255,255,0.9);
  font-size: var(--text-xs);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid rgba(255,255,255,0.12);
  z-index: 100;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-1) 0;
}

.settings-label {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
}

.settings-value {
  letter-spacing: 0.04em;
}

.settings-toggle {
  cursor: pointer;
}

.settings-toggle input[type="checkbox"] {
  appearance: none;
  width: 1em;
  height: 1em;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: var(--radius);
  background: transparent;
  transition: background var(--transition), border-color var(--transition);
}

.settings-toggle input[type="checkbox"]:checked {
  background: rgba(255,255,255,0.9);
  border-color: rgba(255,255,255,0.9);
}

/* ════════════════════════════════════════════════
   RESULTS SCREEN
   ════════════════════════════════════════════════ */
.results-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--sp-12) var(--sp-6) var(--sp-16);
  gap: var(--sp-8);
  overflow-y: auto;
}

.results-title {
  font-size: var(--text-lg);
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

/* Hero colour circle */
.winner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
}

.winner-circle {
  width: clamp(140px, 40vmin, 220px);
  height: clamp(140px, 40vmin, 220px);
  border-radius: 50%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.winner-label {
  text-align: center;
}
.winner-name { font-size: var(--text-xl);  font-weight: 300; letter-spacing: 0.05em; }
.winner-hex  { font-size: var(--text-sm);  color: var(--color-text-muted); font-family: var(--font-mono); margin-top: var(--sp-1); }

/* ── Full ranking ── */
.ranking-details {
  width: 100%;
  max-width: 380px;
}

.ranking-details summary {
  font-size: var(--text-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--sp-2) 0;
  list-style: none;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-3);
}
.ranking-details summary::-webkit-details-marker { display: none; }
.ranking-details[open] summary::after { content: ' ↑'; }
.ranking-details:not([open]) summary::after { content: ' ↓'; }

.ranking-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.rank-number {
  width: 1.8rem;
  text-align: right;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.rank-swatch {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--radius);
  flex-shrink: 0;
  border: 1px solid var(--color-border);
}

.rank-name {
  font-size: var(--text-sm);
  color: var(--color-text);
}

/* ── Results actions ── */
.results-actions {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  justify-content: center;
}

/* ════════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════════ */
.btn-primary {
  background: var(--color-text);
  color: var(--color-bg);
  border: none;
  padding: var(--sp-3) var(--sp-8);
  font-size: var(--text-base);
  font-weight: 400;
  letter-spacing: 0.12em;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--color-accent); }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-text);
  padding: var(--sp-2) var(--sp-6);
  font-size: var(--text-sm);
  letter-spacing: 0.08em;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
}
.btn-secondary:hover { background: var(--color-text); color: var(--color-bg); }

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  transition: color var(--transition);
}
.btn-ghost:hover { color: var(--color-text); }

/* Ghost on dark background (compare screen) */
.btn-ghost--light        { color: rgba(255,255,255,0.5); }
.btn-ghost--light:hover  { color: rgba(255,255,255,0.9); }

/* ════════════════════════════════════════════════
   FOOTER
   ════════════════════════════════════════════════ */
.app-footer {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

.app-footer a {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
  text-transform: uppercase;
  text-decoration: none;
  transition: color var(--transition);
}
.app-footer a:hover { color: var(--color-text); }

/* ════════════════════════════════════════════════
   ALGORITHMS PAGE
   ════════════════════════════════════════════════ */
.algo-page {
  max-width: 780px;
  margin: 0 auto;
  padding: var(--sp-12) var(--sp-6) var(--sp-16);
}

.algo-page header {
  margin-bottom: var(--sp-12);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--sp-6);
}

.algo-page header h1 {
  font-size: var(--text-xl);
  font-weight: 300;
  letter-spacing: 0.08em;
}
.algo-page header p {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: var(--sp-2);
}

.algo-section {
  margin-bottom: var(--sp-16);
}

.algo-section h2 {
  font-size: var(--text-lg);
  font-weight: 400;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--color-border);
}

.algo-section h3 {
  font-size: var(--text-base);
  font-weight: 500;
  margin: var(--sp-6) 0 var(--sp-2);
}

.algo-section p {
  color: var(--color-text);
  line-height: 1.8;
  margin-bottom: var(--sp-4);
  max-width: 65ch;
}

.algo-section ul, .algo-section ol {
  padding-left: var(--sp-6);
  margin-bottom: var(--sp-4);
  line-height: 1.8;
  max-width: 65ch;
}

/* Mermaid diagram container */
.diagram-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-6);
  overflow-x: auto;
  margin: var(--sp-6) 0;
}

/* Elo formula display */
.formula-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  padding: var(--sp-4) var(--sp-6);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 2;
  margin: var(--sp-4) 0;
}

/* Back link on algo page */
.algo-back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--sp-6);
  text-decoration: none;
  transition: color var(--transition);
}
.algo-back:hover { color: var(--color-text); text-decoration: none; }

/* ════════════════════════════════════════════════
   TOAST
   ════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: var(--sp-8);
  left: 50%;
  transform: translateX(-50%) translateY(var(--sp-6));
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  padding: var(--sp-2) var(--sp-6);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ════════════════════════════════════════════════
   UTILITIES
   ════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* Keyboard shortcut hint visible only on non-touch */
.kbd-hint {
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.3);
  letter-spacing: 0.05em;
  text-align: center;
  padding: var(--sp-1) 0 var(--sp-2);
  background: rgba(0,0,0,0.6);
  flex-shrink: 0;
}
@media (hover: none) { .kbd-hint { display: none; } }
