/* ---------------------------------------------------------------------------
   Untangle — "Quiet Room"

   One screen that looks like somewhere you could think. Tokens for both
   themes are defined together; nothing has its only definition inside a
   media query. See assets/design/design-system.md.
   --------------------------------------------------------------------------- */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --text: #14130f;
  --muted: #6b6760;
  --accent: #b4532a;
  --accent-soft: rgba(180, 83, 42, 0.1);
  /* Text that sits ON the accent. White passes on the deep terracotta of the
     light theme and fails badly on the lifted accent the dark theme needs. */
  --on-accent: #ffffff;
  --line: rgba(20, 19, 15, 0.1);
  --shadow: 0 1px 2px rgba(20, 19, 15, 0.04), 0 8px 24px rgba(20, 19, 15, 0.05);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius-card: 8px;
  --radius-input: 14px;
  --radius-pill: 999px;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;

  --ease: cubic-bezier(0.2, 0, 0.1, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0c;
    --surface: #16161a;
    --text: #f2f0ec;
    --muted: #9a958c;
    --accent: #e8845c;
    --accent-soft: rgba(232, 132, 92, 0.12);
    --on-accent: #1a0d07;
    --line: rgba(242, 240, 236, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0d0d0c;
  --surface: #16161a;
  --text: #f2f0ec;
  --muted: #9a958c;
  --accent: #e8845c;
  --accent-soft: rgba(232, 132, 92, 0.12);
  --on-accent: #1a0d07;
  --line: rgba(242, 240, 236, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-7) var(--space-5) var(--space-5);

  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;

  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

main {
  width: 100%;
  max-width: 640px;
  flex: 1;
  display: flex;
}

/* --- stages ------------------------------------------------------------- */

/* An author display rule outranks the browser's own [hidden] { display: none },
   so .stage { display: flex } would otherwise render every state at once. */
[hidden] {
  display: none !important;
}

.stage {
  width: 100%;
  /* Auto margins centre this vertically without making overflow unreachable.
     justify-content: center would clip a tall result on a short screen with
     no way to scroll to it. */
  margin-block: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-5);
  animation: arrive 240ms var(--ease) both;
}

@keyframes arrive {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
  letter-spacing: -0.01em;
}

.lede {
  margin: calc(var(--space-5) * -1 + var(--space-2)) 0 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: 16px;
}

.hint,
.privacy,
.attribution,
.timer {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.privacy {
  max-width: 34ch;
  font-size: 13px;
}

.status {
  margin: 0;
  font-size: 20px;
  font-family: var(--serif);
}

/* --- the record button: the only thing on screen at rest ---------------- */

.record {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-4) var(--space-6);

  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);

  font-family: var(--sans);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;

  box-shadow: var(--shadow);
  transition: transform 140ms var(--ease), filter 140ms var(--ease);
}

.record:hover {
  filter: brightness(1.06);
}

.record:active {
  transform: scale(0.98);
}

.record-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--on-accent);
  opacity: 0.9;
}

.primary {
  min-height: 48px;
  padding: var(--space-3) var(--space-6);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 140ms var(--ease), filter 140ms var(--ease);
}

.primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.primary:active:not(:disabled) {
  transform: scale(0.98);
}

.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Secondary actions are quiet enough never to compete with the primary. */
.link {
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line);
  cursor: pointer;
}

.link:hover {
  color: var(--text);
}

.alt {
  margin: calc(var(--space-5) * -1 + var(--space-1)) 0 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-card);
}

/* --- waveform ----------------------------------------------------------- */

.wave {
  width: 100%;
  max-width: 420px;
  height: 90px;
  display: block;
}

.wave-replay {
  opacity: 0.55;
}

.timer {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer-max {
  opacity: 0.5;
}

/* --- typing ------------------------------------------------------------- */

textarea {
  width: 100%;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}

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

.quote {
  margin: 0;
  max-width: 22ch;
  font-family: var(--serif);
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.quote::before {
  content: "\201C";
}

.quote::after {
  content: "\201D";
}

.attribution {
  margin-top: calc(var(--space-5) * -1 + var(--space-2));
  font-style: italic;
}

.worry {
  margin: 0;
  max-width: 38ch;
  font-size: 17px;
  line-height: 1.6;
}

.decisions {
  width: 100%;
  max-width: 420px;
  text-align: left;
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

.decisions-title {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.decisions ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.decisions li {
  position: relative;
  padding-left: var(--space-5);
  font-size: 16px;
}

.decisions li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* The single dominant element once a result exists. */
.action-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  border-radius: var(--radius-input);
  background: var(--accent-soft);
}

.action-label {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.action {
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
  text-wrap: balance;
}

.error-message {
  margin: 0;
  max-width: 34ch;
  font-size: 17px;
}

/* --- chrome ------------------------------------------------------------- */

.theme-toggle {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
}

footer {
  display: flex;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  body {
    padding: var(--space-7) var(--space-4) var(--space-4);
  }

  .quote {
    max-width: none;
  }
}

/* Motion is a nicety, never a requirement. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
