/* Perfect Shapes — styles.css
 * Vector-oscilloscope look: near-black glass, mint phosphor, one accent.
 * Type does the heavy lifting — huge tight numerals against small wide-tracked
 * mono labels — so the whole thing stays a few kilobytes and still reads as a
 * built object rather than a template.
 */

/* ---------- themes ----------
 *
 * Every colour the app uses is one of nine variables, so a theme is a short
 * list rather than a stylesheet. The canvas reads the same variables at runtime
 * (see render.js), which is why the drawing changes with the chrome instead of
 * staying mint on a light background.
 *
 * --on-accent is the ink that sits ON the accent colour, and has to be part of
 * the theme rather than assumed dark: the light theme's accent is a deep green
 * that needs white text on it, where every other theme wants near-black.
 */

:root,
:root[data-theme="dark"] {
  --bg:         #05070C;
  --bg-lift:    #0B1018;
  --ink:        #E8F1F5;
  --ink-dim:    #7C8A99;
  --ink-faint:  #46525F;
  --accent:     #35F0C0;
  --on-accent:  #04120E;
  --warn:       #FFB454;
  --bad:        #FF5D73;
  --line:       color-mix(in srgb, var(--ink) 10%, transparent);
  --glow:       0.75;
}

/* Synthwave. Loud on purpose, and the only theme that leans on glow. */
:root[data-theme="neon"] {
  --bg:         #0A0118;
  --bg-lift:    #1A0733;
  --ink:        #FDF4FF;
  --ink-dim:    #B98FD9;
  --ink-faint:  #7A519E;
  --accent:     #FF3DD8;
  --on-accent:  #21001A;
  --warn:       #FFE156;
  --bad:        #FF4E64;
  --line:       rgba(255, 61, 216, 0.22);
  --glow:       1;
}

/* Paper. The accent is a deep green rather than the mint used elsewhere,
 * because mint on white is around 1.6:1 and unreadable. */
:root[data-theme="light"] {
  --bg:         #F2F5F7;
  --bg-lift:    #FFFFFF;
  --ink:        #0E1620;
  --ink-dim:    #55636F;
  --ink-faint:  #8E9BA7;
  --accent:     #0A7A5C;
  --on-accent:  #FFFFFF;
  --warn:       #B45309;
  --bad:        #B3243A;
  --line:       rgba(14, 22, 32, 0.14);
  --glow:       0.25;
}

/* Phosphor terminal. Pure black, one green, nothing else. */
:root[data-theme="matrix"] {
  --bg:         #000000;
  --bg-lift:    #03120A;
  --ink:        #B9FFC9;
  --ink-dim:    #3FBF62;
  --ink-faint:  #1E7038;
  --accent:     #00FF6A;
  --on-accent:  #001C0A;
  --warn:       #C6FF3F;
  --bad:        #FF3B3B;
  --line:       rgba(0, 255, 106, 0.16);
  --glow:       0.9;
}

/* Cold instrumentation: steel, ice blue, and an amber warning light. */
:root[data-theme="robotic"] {
  --bg:         #0E1114;
  --bg-lift:    #181D22;
  --ink:        #DCE3E8;
  --ink-dim:    #8A97A3;
  --ink-faint:  #56636E;
  --accent:     #58C7F0;
  --on-accent:  #04202B;
  --warn:       #FF9F1C;
  --bad:        #EF4444;
  --line:       rgba(220, 227, 232, 0.13);
  --glow:       0.5;
}

:root {
  --gutter: 24px;
  --radius: 14px;

  /* Real, settable viewport height. iOS reports 100vh as the height WITHOUT the
   * URL bar, so a 100vh layout hides its own bottom controls behind it. */
  --vh: 100dvh;
}

@supports not (height: 100dvh) {
  :root { --vh: 100vh; }
}

*, *::before, *::after { box-sizing: border-box; }

/* Several components set an explicit display, which outranks the [hidden]
 * attribute's user-agent rule and leaves supposedly-hidden elements on screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;         /* kill pull-to-refresh mid-trace */
  background: var(--bg);
  color: var(--ink);
}

body {
  position: fixed;
  inset: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* A long press during the gesture otherwise raises iOS's selection loupe and
   * the game becomes unplayable. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  height: var(--vh);
  width: 100%;
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding:
    calc(env(safe-area-inset-top, 0px) + 28px)
    calc(env(safe-area-inset-right, 0px) + var(--gutter))
    calc(env(safe-area-inset-bottom, 0px) + 24px)
    calc(env(safe-area-inset-left, 0px) + var(--gutter));
}

.screen[data-active] { display: flex; }

/* The trace screen must not sit over the drawing, so it only holds edge chrome
 * and lets touches through to the canvas. Anything the player is meant to be
 * able to press has to opt back in, or it is simply not clickable. */
.screen-trace { justify-content: space-between; pointer-events: none; }
.screen-trace .trace-foot > * { pointer-events: auto; }

/* ---------- type ---------- */

.label {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.wordmark {
  margin: 0;
  /* Two words stacked. Sized to viewport width rather than a fixed scale, and
   * deliberately NOT nowrap: the line break is in the markup, so the lockup is
   * the same shape on every screen instead of reflowing at narrow widths. */
  font-size: clamp(36px, 13vw, 62px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.9;
  color: var(--ink);
}

.tagline {
  margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.big-line {
  margin: 0;
  font-size: clamp(28px, 9vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.sub-line {
  margin: 10px 0 0;
  color: var(--ink-dim);
  font-size: 15px;
  max-width: 30ch;
}

/* ---------- intro ---------- */

.best-slot {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-lift);
}

.best-value {
  margin-left: auto;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.how ol {
  margin: 0;
  padding-left: 1.1em;
  display: grid;
  gap: 11px;
}

.how li {
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink-dim);
}

.how b { color: var(--ink); font-weight: 600; }

/* ---------- shape picker ---------- */

/* Kept as one block so the hint stays attached to the buttons it describes,
 * rather than being pushed away by the screen's space-between layout. */
.pick-group { display: grid; gap: 11px; }

.shape-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.shape-btn {
  appearance: none;
  aspect-ratio: 1;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-lift);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.shape-btn svg { width: 100%; height: 100%; display: block; }
.shape-btn svg * { fill: none; stroke: var(--ink-faint); stroke-width: 7; stroke-linejoin: round; stroke-linecap: round; }

.shape-btn[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.shape-btn[aria-pressed="true"] svg * { stroke: var(--accent); }

.shape-hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-dim);
  min-height: 1.4em;
}

.hud-mid { text-align: center; justify-items: center; }
.hud-value.is-small { color: var(--bad); }
.hud-value.is-ok { color: var(--accent); }

/* ---------- buttons ---------- */

.actions { display: grid; gap: 10px; }
.actions-trace { margin-top: auto; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  /* Comfortably past the 44px minimum, and never flush to the bottom edge
   * where an upward tap becomes the iOS home gesture instead. */
  min-height: 60px;
  padding: 0 22px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: transform 90ms ease, background-color 140ms ease, opacity 140ms ease;
}

.btn:active { transform: scale(0.975); }

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
              0 10px 30px -12px color-mix(in srgb, var(--accent) calc(var(--glow) * 90%), transparent);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-dim);
  min-height: 50px;
  font-size: 12.5px;
}

.btn-ghost[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.pip {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  font-size: 10px;
  letter-spacing: 0.14em;
}

.btn-ghost[aria-pressed="true"] .pip { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }

/* ---------- theme swatches ---------- */

.theme-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-top: 2px;
}

.theme-swatch {
  appearance: none;
  position: relative;
  /* Explicit block width: the only child is absolutely positioned, so an
   * inline-block button collapses to nothing and the swatch renders as a
   * hairline. */
  display: block;
  width: 100%;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 140ms ease, transform 90ms ease;
}

.theme-swatch:active { transform: scale(0.96); }

/* Each swatch previews its own theme rather than the current one: the
 * background is that theme's page colour and the bar is its accent, so the row
 * shows what you are choosing between at a glance. */
.theme-swatch i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 15px;
  height: 15px;
  margin: -7.5px 0 0 -7.5px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
}

.theme-swatch[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.theme-name {
  display: block;
  margin-top: 5px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 8.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
}

.theme-swatch[aria-pressed="true"] + .theme-name { color: var(--accent); }

.theme-cell { display: block; }

/* ---------- calibrate ---------- */

.center-stack {
  margin: auto 0;
  display: grid;
  gap: 14px;
  justify-items: start;
}

/* ---------- tracing HUD ---------- */

.hud { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-item { display: grid; gap: 4px; }
.hud-right { text-align: right; justify-items: end; }

.hud-value {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.closure-gauge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

.closure-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 80ms linear;
}

/* ---------- tracing footer ---------- */

.trace-foot {
  margin-top: auto;
  display: grid;
  gap: 10px;
  justify-items: center;
}

/* The only instruction on screen while drawing, so it fades once the player is
 * clearly under way and does not sit over the drawing. */
.lift-hint {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: opacity 400ms ease;
}

.lift-hint.is-drawing { opacity: 0; }

.btn-cancel {
  min-height: 44px;
  padding: 0 26px;
  font-size: 11px;
  opacity: 0.75;
}

.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- add to home screen ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.55);
  padding: var(--gutter);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--gutter));
}

.sheet-card {
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px;
  display: grid;
  gap: 12px;
}

.sheet-card h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sheet-card p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ink-dim); }

.sheet-steps {
  margin: 0;
  padding-left: 1.15em;
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-dim);
}

.sheet-steps b { color: var(--ink); font-weight: 600; }

.glyph {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}

/* ---------- result ---------- */

.result-head { margin-top: 4px; }

/* The reveal — the drawn path against the perfect circle — is the payoff, so
 * it gets its own reserved band. The canvas is full-bleed behind everything,
 * and without this the stats panel lands right on top of the drawing. */
.trace-slot { flex: 1 1 auto; min-height: 150px; }

.score {
  font-size: clamp(66px, 24vw, 108px);
  font-weight: 700;
  /* tabular-nums stops the count-up animation shuffling sideways per frame */
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.055em;
  line-height: 1;
  color: var(--accent);
  margin: 6px 0 0;
}

.score.is-poor { color: var(--bad); }
.score.is-mid  { color: var(--warn); }

.grade {
  margin-top: 10px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.grade-note {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-size: 14px;
  max-width: 34ch;
  min-height: 2.6em;
}

.stats {
  margin: 0;
  /* Never let the flex column squeeze these to nothing when space is tight —
   * shrinking them was how the landscape layout overflowed instead of adapting. */
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.stats > div { background: var(--bg); padding: 13px 14px; }

.stats dt {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 9.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stats dd {
  margin: 5px 0 0;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.pb-flag {
  margin: 14px 0 4px;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.26em;
  color: var(--accent);
}

/* ---------- blocked ---------- */

/* ---------- motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Short portrait screens — an SE is 568px tall, and the result screen at full
 * size needs about 640. Everything gives up a little rather than one element
 * being crushed. */
@media (orientation: portrait) and (max-height: 700px) {
  .screen {
    padding-top: calc(env(safe-area-inset-top, 0px) + 18px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  }
  .wordmark { font-size: 34px; }
  .tagline { font-size: 9.5px; letter-spacing: 0.12em; }
  .how li { font-size: 13.5px; }
  .score { font-size: 58px; }
  .grade { margin-top: 6px; font-size: 17px; }
  .grade-note { min-height: 0; font-size: 13px; }
  .trace-slot { min-height: 104px; }
  .stats > div { padding: 10px 12px; }
  .stats dd { font-size: 15px; }
  .pb-flag { margin: 9px 0 10px; }
  .btn { min-height: 52px; }
}

/* Landscape on a phone leaves no vertical room for the stacked layout, so the
 * chrome tightens rather than overflowing. screen.orientation.lock() is not
 * available in Safari, so this has to be handled in CSS. */
@media (orientation: landscape) and (max-height: 500px) {
  .screen {
    padding-top: calc(env(safe-area-inset-top, 0px) + 14px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  }
  .how { display: none; }
  .shape-hint { display: none; }
  .wordmark { font-size: 30px; }
  .tagline { font-size: 9px; }
  .shape-btn { padding: 5px; }
  .btn { min-height: 48px; }
  .theme-swatch { height: 28px; }
  .theme-name { display: none; }
  .center-stack { gap: 10px; }
  .big-line { font-size: 26px; }

  /* Stacking the result screen leaves no vertical room for the reveal, and the
   * drawing is the point of it. Landscape has width to spare instead, so the
   * numbers take one column and the circle takes the other. */
  #screen-result[data-active] {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    grid-template-rows: auto auto 1fr;
    column-gap: 22px;
    align-content: start;
  }
  #screen-result .result-head { grid-area: 1 / 1; }
  #screen-result .stats       { grid-area: 2 / 1; }
    #screen-result .pb-flag     { grid-area: 3 / 1; align-self: start; margin: 10px 0 0; }
  #screen-result .actions     { grid-area: 3 / 1; align-self: end; }
  #screen-result .trace-slot  { grid-area: 1 / 2 / 4 / 3; min-height: 0; }

  .score { font-size: 54px; margin-top: 2px; }
  .grade { margin-top: 6px; font-size: 16px; }
  .grade-note { min-height: 0; font-size: 13px; margin-top: 5px; }
  .stats { grid-template-columns: repeat(4, 1fr); margin-top: 10px; }
  .stats > div { padding: 9px 10px; }
  .stats dd { font-size: 15px; }
}
