/* Tasks minigame — Anthropic brand palette, mobile-first.
   Mechanic: token prediction (port of src/public/js/assessment.js). */
:root {
  --bg:        #e8e6dc;  /* Anthropic Light Gray */
  --ink:       #141413;  /* Anthropic Dark */
  --muted:     #b0aea5;  /* Anthropic Mid Gray */
  --accent:    #d97757;  /* Anthropic Orange */
  --good:      #788c5d;  /* Anthropic Green */
  --blue:      #6a9bcc;  /* Anthropic Blue */
  --rule:      #e8e6dc;
  --surface:   #faf9f5;  /* Anthropic Light */
  --border:    #b0aea5;

  --serif: ui-serif, Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --sans:  -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono:  ui-monospace, 'SF Mono', 'JetBrains Mono', 'Menlo', monospace;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.15; }
h2 { font-size: clamp(1.15rem, 2.6vw, 1.45rem); line-height: 1.2; }
.mono { font-family: var(--mono); }

/* HUD */
.hud {
  position: sticky; top: 0; z-index: 5;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.hud__cell {
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.hud__label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.hud__value {
  font-family: var(--mono);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud__cell--flag .hud__value { font-size: 0.75rem; letter-spacing: 0.04em; }

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 1rem;
  gap: 1rem;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.model-line {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.5;
  border-left: 2px solid var(--accent);
  padding: 0.25rem 0 0.25rem 0.85rem;
  color: var(--ink);
  margin: 0;
}

/* Predictor */
.predictor__caption {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0;
}

.predictor__tokens {
  font-family: var(--mono);
  font-size: 1.05rem;
  line-height: 1.9;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.85rem 0.95rem;
  min-height: 3.6rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.05rem;
  word-break: break-word;
}

.predictor__token {
  display: inline-block;
  white-space: pre;
  padding: 0.05rem 0.05rem;
  border-radius: 2px;
  transition: background-color 200ms ease;
}
.predictor__token--prefix { color: var(--muted); }
.predictor__token--chosen { color: var(--ink); background: rgba(120, 140, 93, 0.08); }
.predictor__token--just-added {
  background: rgba(120, 140, 93, 0.28);
  animation: tok-flash 320ms ease-out;
}
@keyframes tok-flash {
  from { background: rgba(120, 140, 93, 0.55); }
  to   { background: rgba(120, 140, 93, 0.08); }
}

.predictor__caret {
  display: inline-block;
  width: 2px; height: 1.1em;
  background: var(--ink);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

.predictor__ack {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* Token candidate buttons */
.token-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}
@media (min-width: 520px) {
  .token-row { grid-template-columns: 1fr 1fr; }
}
.token-row--disabled { opacity: 0.5; pointer-events: none; }

.token {
  font: inherit;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 0.85rem 1rem;
  cursor: pointer;
  min-height: 56px;
  text-align: left;
  transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
  -webkit-tap-highlight-color: transparent;
}
.token:hover { background: var(--bg); border-color: var(--muted); }
.token:active { transform: translateY(1px); }
.token:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.token[disabled] { opacity: 0.55; cursor: default; }

.token--selected {
  background: rgba(120, 140, 93, 0.15);
  border-color: var(--good);
}

.token__key {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0 0.35rem;
  border-radius: 2px;
  min-width: 1.5rem;
  text-align: center;
}
.token__label {
  font-family: var(--mono);
  font-size: 0.95rem;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.token__prob {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* Buttons (intro / end / skip) */
.btn {
  font: inherit;
  font-size: 0.95rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 0.85rem 1rem;
  cursor: pointer;
  min-height: 48px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--bg); border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn--primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.btn--primary:hover { background: var(--ink); filter: brightness(0.85); }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-align: right;
  width: auto;
  align-self: flex-end;
  padding: 0.5rem 0;
  min-height: 0;
  font-size: 0.85rem;
}
.btn--ghost:hover { color: var(--ink); background: transparent; }

/* Ticker */
.ticker {
  border-top: 1px solid var(--border);
  background: var(--ink);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.55rem 1rem calc(0.55rem + var(--safe-bottom));
  min-height: 2.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ticker::before {
  content: "●";
  color: var(--accent);
  animation: pulse 1.4s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Intro specs */
.intro-specs {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}
.intro-spec {
  display: grid;
  grid-template-columns: minmax(6rem, 8rem) 1fr;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.82rem;
}
.intro-spec:last-child { border-bottom: none; }
.intro-spec__key { color: var(--muted); }
.intro-spec__val { color: var(--ink); }
.intro-spec__val--pending { color: var(--muted); }

/* Fine print */
.fine-print {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

/* End screen */
.end__stat {
  display: flex; justify-content: space-between;
  border-bottom: 1px dashed var(--border);
  padding: 0.4rem 0;
  font-family: var(--mono);
  font-size: 0.9rem;
}
.end__stat:last-of-type { border-bottom: none; }
.end__stat span:last-child { color: var(--muted); }

.card { animation: enter 240ms ease-out both; }
@keyframes enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .ticker::before, .predictor__caret, .predictor__token--just-added { animation: none; }
}
