/*
 * ikutan design tokens and base styles.
 *
 * Dark-first by design: auditoriums are dark, and a full-brightness white phone
 * screen in a dark hall is rude to the people behind you. Light theme is an
 * explicit opt-in, remembered per device.
 *
 * Every contrast ratio in DESIGN.md was measured against these values.
 */

:root {
  /* Dark is the default, not a media query. */
  --bg: #0b0b0c;
  --surface: #141416;
  --surface-2: #1c1c1f;
  --border: #2a2a2e;
  --border-strong: #3a3a40;
  --text: #f4f4f5;
  --text-muted: #a1a1a8;
  --text-faint: #71717a;
  --accent: #4ade80;
  --accent-ink: #04140a;
  --accent-dim: #1e5f38;
  --warn: #fbbf24;
  --danger: #f87171;
  --scrim: rgba(11, 11, 12, 0.72);
  --focus: #4ade80;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;

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

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 120ms;
  --dur-base: 220ms;
  --dur-slow: 420ms;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --z-deck: 1;
  --z-controls: 10;
  --z-pill: 20;
  --z-overlay: 30;
  --z-toast: 40;
}

/*
 * Light theme, opt-in.
 *
 * The deck surface stays dark even here: a white slide at full brightness is
 * exactly what this product exists to avoid. Only the app chrome flips.
 */
:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #52525b;
  --text-faint: #71717a;
  --accent: #15803d;
  --accent-ink: #ffffff;
  --accent-dim: #bbf7d0;
  --warn: #a16207;
  --danger: #b91c1c;
  --scrim: rgba(250, 250, 250, 0.82);
  --focus: #15803d;
}

@media (prefers-contrast: more) {
  :root {
    --border: var(--border-strong);
    --text-muted: var(--text);
    --text-faint: var(--text-muted);
  }
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent iOS text inflation on landscape rotation. */
  -webkit-text-size-adjust: 100%;
}

/* Visible focus everywhere. This is a keyboard-first tool. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---------------------------------------------------------------- typography */

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

h1 {
  font-size: clamp(24px, 5vw, 32px);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
  font-weight: 600;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

/* ------------------------------------------------------------------ layout */

.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.wrap-narrow {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.spacer {
  flex: 1;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: var(--z-controls);
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 13px;
  color: var(--text-muted);
}

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

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  letter-spacing: -0.005em;
  padding: 0 var(--space-4);
  height: 40px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    transform 90ms var(--ease);
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

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

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-lg {
  height: 48px;
  font-size: 15px;
  padding: 0 var(--space-6);
}

/* 44px minimum touch target on anything interactive. */
.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--r-md);
}

/* -------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-4);
}

.card-lg {
  border-radius: var(--r-lg);
  padding: var(--space-6);
}

/* ------------------------------------------------------------------- inputs */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.label {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-muted);
}

.input {
  font: inherit;
  font-size: 16px; /* 16px prevents iOS zoom on focus. Not a style choice. */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  height: 44px;
  padding: 0 var(--space-3);
  width: 100%;
}

.input::placeholder {
  color: var(--text-faint);
}

.input:focus {
  border-color: var(--accent);
}

.input-code {
  font-family: var(--font-mono);
  font-size: 24px;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  height: 56px;
  font-weight: 600;
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
}

.error {
  font-size: 13px;
  color: var(--danger);
  font-weight: 550;
}

/* ------------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-live {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.badge-warn {
  color: var(--warn);
}

.badge-danger {
  color: var(--danger);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  flex: none;
}

/* A live dot is the one piece of decoration in the app, and it carries state. */
.badge-live .dot {
  animation: pulse 2s var(--ease) infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* -------------------------------------------------------------------- lists */

.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  min-height: 56px;
}

.list-item:last-child {
  border-bottom: none;
}

a.list-item:hover {
  background: var(--surface-2);
}

/* ------------------------------------------------------------- empty states */

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}

/* --------------------------------------------------------------- utilities */

.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
}

.small {
  font-size: 13px;
}

.tiny {
  font-size: 12px;
}

.center {
  text-align: center;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/*
 * The `hidden` attribute is authoritative.
 *
 * A class rule with `display: grid` or `display: inline-flex` beats the browser
 * default of `[hidden] { display: none }`, so an element with the attribute set
 * stays visible. Making this explicit means JS only ever toggles `hidden`.
 */
[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------- join card */

/*
 * The join affordance.
 *
 * Visually distinct from the speaker's own content because it serves a different
 * person: an audience member who was handed a code and needs to know exactly
 * where to type it.
 */
.join-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: var(--space-5);
}

.join-card-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

@media (min-width: 640px) {
  .join-card-form {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }
}
