:root {
  --bg: #fbf7f2;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #b35900;
  --line: #e8e3dc;
  --radius: 10px;
  --serif: ui-serif, 'Iowan Old Style', 'Apple Garamond', Baskerville, 'Times New Roman', serif;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --ink: #f4efe6;
    --muted: #8c8579;
    --accent: #e08a2a;
    --line: #2a2620;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

header {
  text-align: center;
  padding: 2.25rem 1rem 0.5rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: 3.25rem;
  margin: 0 0 0.2rem;
  letter-spacing: -0.02em;
  font-weight: 500;
  font-style: italic;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-family: var(--serif);
}

main {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}

footer {
  text-align: center;
  padding: 1.25rem 1rem 1.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

footer .brand {
  font-family: var(--serif);
  font-style: italic;
}

.screen { display: none; }
.screen.active { display: block; animation: fadein 0.3s ease; }

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

.puzzle-no {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 1.25rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.rules {
  font-size: 1.05rem;
  text-align: center;
  margin: 0 0 2rem;
  color: var(--ink);
}

.primary {
  display: block;
  margin: 1.75rem auto 0;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 0.9rem 2.25rem;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-width: 12rem;
}
.primary:hover { background: var(--accent); }
.primary:active { transform: translateY(1px); }
.primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.round-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.round-counter {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
}

.big-swatch {
  width: 100%;
  aspect-ratio: 1.6 / 1;
  border-radius: var(--radius);
  background: var(--line);
  transition: opacity 0.4s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

.phase { display: none; }
.phase.visible { display: block; animation: fadein 0.25s ease; }

/* ---------- picker (HS field + lightness bar) ---------- */

.picker {
  margin: 1.25rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  touch-action: none;
}

.picker-field {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), inset 0 0 0 1px rgba(0,0,0,0.06);
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

.picker-bar {
  position: relative;
  width: 100%;
  height: 44px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), inset 0 0 0 1px rgba(0,0,0,0.06);
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
}

.picker-field canvas,
.picker-bar canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.picker-cursor {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85), 0 1px 3px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
  background: transparent;
  top: 0;
  left: 0;
}

.picker-cursor--bar {
  width: 26px;
  height: 40px;
  border-radius: 6px;
}

/* reveal-mode cursors: target = gold outline, guess = white outline */
.picker-cursor--target {
  border-color: #d4a017;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.3);
}

.picker-cursor--guess {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.3);
}

.picker-field:focus-visible,
.picker-bar:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.picker--reveal .picker-field,
.picker--reveal .picker-bar {
  cursor: default;
}

#guess-swatch { margin-bottom: 0; }

.reveal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.reveal-cell {
  text-align: center;
}

.reveal-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background: var(--line);
}

.reveal-label {
  font-family: var(--serif);
  font-style: italic;
  margin: 0.5rem 0 0.1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.round-score {
  margin-top: 1.25rem;
  font-size: 1.1rem;
  color: var(--ink);
  font-family: var(--serif);
  font-style: italic;
  text-align: center;
}

.round-score span { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 500; }

#finale h2, #already h2 {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 500;
  font-style: italic;
  text-align: center;
  margin: 0.5rem 0 1.25rem;
}

#finale h2 span,
.already-score-line span {
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.already-score-line {
  text-align: center;
  margin: 0 0 1rem;
  color: var(--ink);
  font-size: 1.05rem;
}

.petal-result {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem auto 1.5rem;
  flex-wrap: wrap;
}

.petal {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--line);
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
}

.share-status {
  text-align: center;
  color: var(--muted);
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.next-puzzle {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  margin-top: 1.75rem;
}

/* responsive */
@media (max-width: 420px) {
  .wordmark { font-size: 2.6rem; }
  main { padding: 1.25rem 1rem 2rem; }
  .petal { width: 44px; height: 44px; }
}
