/* ===================================================================
   Wordseed — stylesheet
   A small design system: tokens up top, then layout, then components.
   Mobile-first-ish, but tuned at three breakpoints (phone / tablet / desktop).
   =================================================================== */

:root {
  /* color */
  --bg: #06060c;
  --bg-2: #0a0913;
  --ink: #eceff4;
  --muted: #9aa0b4;
  --dim: #5b5f74;
  --line: #1b1b26;
  --line-2: #2a2a38;
  --field: #0d0d17;
  --accent: #d8b27a;
  --accent-ink: #1a1305;

  /* type */
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;

  /* shape & motion */
  --r: 8px;
  --r-sm: 5px;
  --ease: cubic-bezier(.22, .61, .36, 1);

  /* fluid spacing */
  --gut: clamp(14px, 4vw, 22px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% -10%, #0b0a16 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: var(--sans);
}
body {
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top)) var(--gut)
    calc(28px + env(safe-area-inset-bottom)) var(--gut);
}

/* ---------- header ---------- */
.head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-optical-sizing: auto;
  font-size: clamp(26px, 6vw, 38px);
  letter-spacing: .005em;
  line-height: 1;
}
.brand h1 em { font-style: italic; font-weight: 400; color: var(--accent); }
.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(12px, 3.4vw, 14px);
}
.head .meta {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
}

/* ---------- stage ---------- */
.stage { position: relative; }
.stagewrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  background: #06060c;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: min(70vh, 660px);
  box-shadow: 0 24px 60px -28px rgba(0, 0, 0, .8), inset 0 0 0 1px rgba(255, 255, 255, .02);
}
canvas#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation; /* let taps register fast, no 300ms delay */
}

/* empty-state hint, centered over the canvas */
.hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s var(--ease);
  text-align: center;
  padding: 0 24px;
}
.hint.show { opacity: 1; }
.hint span {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: clamp(14px, 3.6vw, 18px);
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.seedfield {
  flex: 1 1 240px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0 14px;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.seedfield:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.seedfield .lead { color: var(--accent); font-family: var(--serif); font-style: italic; font-size: 15px; }
.seedfield input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(16px, 4.2vw, 18px); /* >=16px keeps iOS from zooming on focus */
  padding: 13px 0;
}
.seedfield input::placeholder { color: var(--dim); font-style: italic; }

button {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .01em;
  padding: 13px 18px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  white-space: nowrap;
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .08s var(--ease), filter .15s var(--ease);
}
button:hover { border-color: var(--line-2); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-ghost { color: var(--muted); }
.spacer { flex: 1 1 0; min-width: 0; }

/* ---------- footer ---------- */
.foot {
  margin-top: 18px;
  color: var(--dim);
  font-size: 12px;
  font-family: var(--serif);
  font-style: italic;
  text-align: center;
  line-height: 1.6;
}
.foot a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line-2); }
.foot a:hover { color: var(--accent); }

/* ---------- specimen card (side panel desktop / bottom sheet phone) ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 10, .55);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease);
  z-index: 40;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.card {
  position: fixed;
  z-index: 50;
  background: linear-gradient(180deg, #0c0b16, #08070f);
  border: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 14px;
  pointer-events: none;
  opacity: 0;

  /* desktop default: right side panel */
  top: 0; right: 0; bottom: 0;
  width: min(380px, 92vw);
  padding: 26px 24px calc(26px + env(safe-area-inset-bottom));
  border-right: none;
  transform: translateX(100%);
  transition: transform .34s var(--ease), opacity .34s var(--ease);
  box-shadow: -30px 0 70px -40px rgba(0, 0, 0, .9);
  overflow-y: auto;
}
.card.open { transform: none; opacity: 1; pointer-events: auto; }

.card .card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(26px, 5vw, 32px);
  color: var(--accent);
  line-height: 1.05;
}
.card .note {
  margin: 0;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
}
.card .close {
  flex: none;
  width: 34px; height: 34px;
  padding: 0;
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
  color: var(--muted);
  background: var(--field);
}

.rows { margin: 4px 0 0; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.rows .row { display: flex; justify-content: space-between; gap: 12px; background: #0a0a13; padding: 11px 13px; }
.rows dt { color: var(--dim); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.rows dd { margin: 0; color: var(--ink); font-size: 13px; font-weight: 500; text-align: right; }

.seedline { display: flex; align-items: center; gap: 10px; margin-top: auto; }
.seedline .lab { color: var(--dim); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.seedline code {
  flex: 1;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seedline button { padding: 9px 12px; font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  background: #14131f;
  border: 1px solid var(--line-2);
  color: var(--ink);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  z-index: 60;
  box-shadow: 0 12px 30px -16px rgba(0, 0, 0, .9);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- accessibility helpers ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ===================================================================
   Breakpoints
   =================================================================== */

/* tablet */
@media (max-width: 900px) {
  .stagewrap { aspect-ratio: 4 / 3; max-height: 64vh; }
}

/* phone: portrait stage gives plants vertical room; controls stack; the
   specimen card becomes a bottom sheet that slides up from the edge. */
@media (max-width: 560px) {
  .head { align-items: flex-start; }
  .head .meta { display: none; }
  .stagewrap { aspect-ratio: 5 / 6; max-height: 62vh; }

  .controls { gap: 8px; }
  .seedfield { flex-basis: 100%; order: -1; }
  .btn-primary { flex: 1 1 auto; }
  .btn-ghost { flex: 1 1 auto; }
  .spacer { display: none; }

  .card {
    top: auto; right: 0; left: 0; bottom: 0;
    width: auto;
    max-height: 82dvh;
    border-radius: 16px 16px 0 0;
    border: 1px solid var(--line);
    transform: translateY(100%);
    box-shadow: 0 -30px 70px -40px rgba(0, 0, 0, .9);
  }
  .card::before {
    content: '';
    position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 38px; height: 4px; border-radius: 4px; background: var(--line-2);
  }
}

/* honor reduced-motion: no slides, no transforms animating */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

/* ===================================================================
   Embed mode — when Wordseed runs inside an <iframe> (e.g. a portfolio
   card) we drop all the page chrome and let the canvas fill the frame at
   whatever ratio the host gives it. Toggled by adding `.embed` to <body>.
   =================================================================== */
body.embed { background: #06060c; overflow: hidden; }
body.embed .app { max-width: none; margin: 0; padding: 0; }
body.embed .head,
body.embed .controls,
body.embed .foot,
body.embed .hint,
body.embed .toast { display: none !important; }
body.embed .stage { position: fixed; inset: 0; }
body.embed .stagewrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none !important;
  aspect-ratio: auto !important;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
body.embed canvas#stage { width: 100%; height: 100%; }
