:root {
  --bg: #1a1612;
  --ink: #f4efe6;
  --muted: #8c8579;
  --accent: #e08a2a;
  --target: #6abf7a;
  --target-bright: #8ed99f;
  --line: #2a2620;
  --urgent: var(--error, #d65a3a);
  --game-focus: var(--border-focus, var(--accent));
  --button-radius: var(--radius-md, 8px);
  --artifact-radius: var(--radius-lg, 12px);
  --sans: var(--font-sans, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  cursor: pointer;
}

/* HUD */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 1.1rem 1.5rem env(safe-area-inset-top, 1.1rem);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 1.25rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#hud.show { opacity: 1; }

#hud #score { color: var(--ink); }
#hud #timer { color: var(--accent); transition: color 0.25s ease; }
#hud #timer.urgent { color: var(--urgent); }

.curveHud {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.curveMeter {
  display: inline-flex;
  gap: 0.3rem;
  justify-content: center;
  align-items: center;
  font-size: 0.66rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.curveMeter.visible {
  opacity: 1;
  transform: translateY(0);
}
.curveMeter span {
  border: 1px solid rgba(140, 133, 121, 0.35);
  border-radius: 999px;
  padding: 0.16rem 0.42rem;
  color: rgba(140, 133, 121, 0.74);
  background: rgba(26, 22, 18, 0.30);
}
.curveMeter span.active {
  color: var(--bg);
  border-color: rgba(224, 138, 42, 0.85);
  background: var(--accent);
  box-shadow: 0 0 14px rgba(224, 138, 42, 0.22);
}

.shrinkTag {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: lowercase;
  opacity: 0.7;
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 2rem 1.5rem;
  text-align: center;
  background: rgba(26, 22, 18, 0.92);
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.screen.active { display: flex; animation: fadein 0.35s ease; }

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

.wordmark {
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 200;
  letter-spacing: -0.04em;
  margin-bottom: 0.6rem;
  color: var(--ink);
  line-height: 0.95;
}

h2 {
  font-size: 1.5rem;
  font-weight: 300;
  margin-bottom: 1rem;
  color: var(--muted);
  letter-spacing: -0.02em;
}

.rules {
  color: var(--muted);
  margin: 0 0 2rem;
  font-size: 1.05rem;
  max-width: 32rem;
  line-height: 1.5;
}

.tagline {
  color: var(--accent);
  margin: 0 0 0.8rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.daily-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 0.85rem;
  padding: 0.32rem 0.72rem;
  border: 1px solid rgba(224, 138, 42, 0.42);
  border-radius: 999px;
  background: rgba(224, 138, 42, 0.08);
  color: #f4d79f;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

button {
  display: block;
  margin: 0.4rem 0.3rem;
  border: none;
  border-radius: var(--button-radius);
  padding: 0.85rem 1.6rem;
  font: inherit;
  font-weight: 500;
  font-size: 0.98rem;
  cursor: pointer;
  min-width: 10rem;
  transition: filter 0.15s, transform 0.05s, background 0.15s, color 0.15s, border-color 0.15s;
  font-family: var(--sans);
}
.primary {
  background: var(--accent);
  color: var(--bg);
}
.primary:hover { filter: brightness(1.12); }
.primary:active { transform: translateY(1px); }
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.ghost:hover { color: var(--ink); border-color: var(--muted); }
.ghost-secondary { font-size: 0.85rem; padding: 0.6rem 1.1rem; min-width: 8rem; opacity: 0.75; }
button:focus-visible {
  outline: 2px solid var(--game-focus);
  outline-offset: 3px;
}

/* End screen — ribbon-first layout */
.ribbon-canvas {
  display: block;
  width: min(86vw, 520px);
  height: min(58vh, 520px);
  margin: 0.4rem 0 1rem;
  border-radius: var(--artifact-radius);
  background: radial-gradient(ellipse at center, #221d17 0%, #15110d 100%);
  box-shadow: 0 6px 28px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(140,133,121,0.08);
}

.result-corner {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom, 1rem), 1rem);
  left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: flex-start;
  font-size: 0.85rem;
  pointer-events: none;
}
.result-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.result-row .label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: lowercase;
  letter-spacing: 0.1em;
  min-width: 3.6rem;
  text-align: left;
}
.result-row .value {
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 2ch;
  text-align: left;
}

.end-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem;
  margin: 0.4rem 0;
}

.status {
  margin-top: 0.4rem;
  min-height: 1.4em;
  font-size: 0.85rem;
  color: var(--muted);
}

.score-hint {
  margin-top: -0.1rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.cta {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom, 1rem), 1rem);
  right: 1.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  line-height: 1.5;
  max-width: 60vw;
  pointer-events: auto;
}
.cta a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.cta a:hover,
.cta a:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
  outline: none;
}

footer {
  position: fixed;
  bottom: 0.85rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  pointer-events: none;
  opacity: 0.45;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#end.active footer { display: none; }
#end.active ~ footer { display: none; }

@media (max-width: 420px) {
  #hud { padding: 0.85rem 1rem; font-size: 1.05rem; }
  .shrinkTag { font-size: 0.68rem; }
  footer { font-size: 0.66rem; }
  .ribbon-canvas { width: 92vw; height: 52vh; }
  .result-corner { left: 0.6rem; }
  .cta { right: 0.6rem; max-width: 55vw; }
}

@media (max-height: 700px) {
  .ribbon-canvas { height: min(50vh, 380px); }
  h2 { margin-bottom: 0.5rem; }
}
