/*
  Design direction: "signal room" — a quiet instrument panel, not a
  marketing page. Two keys, two colors: a cold slate for the public key
  (shareable, safe in the open) and a warm amber for the private key
  (handle with care). Monospace throughout because everything on this
  page is literally text you're expected to copy correctly, character
  for character — the type itself should say "precision."

  Responsive strategy:
    - Fluid by default (rem/%/clamp), not just breakpoint-swapped.
    - Three explicit ranges tuned to real devices, not arbitrary widths:
        phone   : up to 599px  (one column, full-width controls, larger touch targets)
        tablet  : 600–1023px   (comfortable line length, two-up action rows)
        laptop+ : 1024px and up (max content width, most generous spacing)
    - All interactive controls keep a >=44px touch target (Apple/WCAG guidance).
    - All text inputs stay >=16px font-size so iOS Safari never auto-zooms on focus.
*/

:root {
  --ink: #e6e8eb;
  --ink-dim: #9aa3ad;
  --bg: #101317;
  --bg-panel: #161a20;
  --bg-field: #0c0f13;
  --line: #262c34;

  --public: #6fb3c8;      /* cold slate-teal: the key you hand out */
  --private: #d9a441;     /* warm amber: the key you protect */
  --danger: #e06c5c;
  --success: #7bbf8a;

  --mono: "IBM Plex Mono", "SF Mono", Consolas, "Roboto Mono", monospace;
  --sans: "IBM Plex Sans", -apple-system, Segoe UI, sans-serif;

  --radius: 3px;
  --touch: 44px; /* minimum comfortable touch target */

  /* Fluid container width: never edge-to-edge on phones, capped on laptops */
  --content-max: 760px;
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

#app {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: clamp(24px, 6vw, 40px) var(--gutter) 80px;
}

.masthead { margin-bottom: 28px; }
.masthead h1 {
  font-family: var(--mono);
  font-size: clamp(18px, 4vw, 22px);
  letter-spacing: 0.02em;
  margin: 0 0 6px;
  word-break: break-word;
}
.masthead .tagline {
  color: var(--ink-dim);
  font-size: clamp(13px, 3vw, 14px);
  margin: 0;
}

.notice {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  margin-bottom: 24px;
  line-height: 1.5;
}
.notice--success { border-color: var(--success); color: var(--success); }
.notice--error { border-color: var(--danger); color: var(--danger); }

/* ── Tabs ──────────────────────────────────────────────────────────── */
/* Phone-first: horizontally scrollable strip so three tab labels never
   wrap or truncate awkwardly on a 320–375px viewport. */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  font-family: var(--mono);
  font-size: 13px;
  background: none;
  border: none;
  color: var(--ink-dim);
  padding: 12px 14px;
  min-height: var(--touch);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab:hover { color: var(--ink); }
.tab--active { color: var(--ink); border-bottom-color: var(--public); }

.panel { display: none; }
.panel--active { display: block; }

.panel h2 { font-size: clamp(16px, 3.5vw, 17px); margin: 0 0 6px; }
.panel .description { color: var(--ink-dim); font-size: 14px; margin: 0 0 22px; max-width: 58ch; }

fieldset { border: none; padding: 0; margin: 0 0 18px; min-width: 0; }

label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--ink); }
label.for-public { color: var(--public); }
label.for-private { color: var(--private); }

.help-text { font-size: 12px; color: var(--ink-dim); margin: 6px 0 0; }

/* ── Form controls ─────────────────────────────────────────────────── */
/* font-size fixed at 16px (not a smaller px value) specifically to stop
   iOS Safari's auto-zoom-on-focus behavior on text inputs/textareas. */
textarea, input[type="password"], input[type="text"], select {
  width: 100%;
  background: var(--bg-field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 16px;
  padding: 12px;
  min-height: var(--touch);
}
textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
textarea.key-field { border-left: 3px solid var(--line); }
textarea.key-field--public { border-left-color: var(--public); }
textarea.key-field--private { border-left-color: var(--private); }

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%),
                     linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--public);
}

.field--invalid { border-color: var(--danger) !important; }
.field-error { color: var(--danger); font-size: 12px; margin: 6px 0 0; font-family: var(--mono); }

.checkbox-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; min-height: var(--touch); }
.checkbox-row input {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin-top: 3px;
  flex-shrink: 0;
}
.checkbox-row label { margin: 0; }

/* ── Buttons ───────────────────────────────────────────────────────── */
button[type="submit"] {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--public);
  color: #0c0f13;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  min-height: var(--touch);
  cursor: pointer;
  font-weight: 600;
  width: 100%;
}
button[type="submit"]:disabled { opacity: 0.6; cursor: progress; }
button[type="submit"]:hover:not(:disabled) { filter: brightness(1.08); }

.result-block { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); display: none; }
.result-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.result-actions--combined { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }

.btn-secondary {
  font-family: var(--mono);
  font-size: 12.5px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: var(--touch);
  cursor: pointer;
  flex: 1 1 auto;
}
.btn-secondary:hover { border-color: var(--ink-dim); }

.warning-box {
  font-size: 12.5px;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 20px;
  background: rgba(224, 108, 92, 0.06);
  line-height: 1.5;
}

/* ── Breakpoint: tablet and up (600px+) ──────────────────────────────
   More breathing room; submit buttons no longer need to be full-width;
   action buttons sit inline instead of stretching. */
@media (min-width: 600px) {
  button[type="submit"] { width: auto; }
  .btn-secondary { flex: 0 0 auto; }
  .tabs { overflow-x: visible; }
}

/* ── Breakpoint: laptop and up (1024px+) ─────────────────────────────
   Slightly larger type and spacing now that there's room; textareas for
   key material get a bit taller so a full key is visible without
   scrolling on a normal-height window. */
@media (min-width: 1024px) {
  #app { padding-top: 48px; }
  .panel .description { font-size: 14.5px; }
  textarea.key-field--private { min-height: 160px; }
  textarea.key-field--public { min-height: 120px; }
}

/* ── Breakpoint: small phones (<380px) ───────────────────────────────
   Tighten padding further on the narrowest common viewports (e.g. an
   older iPhone SE at 320–375px) so nothing feels cramped or clipped. */
@media (max-width: 379px) {
  #app { padding-left: 12px; padding-right: 12px; }
  .tab { padding: 12px 10px; font-size: 12px; }
}

/* ── Reduced motion / touch refinement ───────────────────────────────
   No animations in this UI beyond hover filters, but keep this here as
   a guard for any future additions. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── Landscape phones (short viewport height) ────────────────────────
   Reduce vertical padding so the submit button isn't pushed off-screen
   under the keyboard on a landscape phone. */
@media (max-height: 480px) and (orientation: landscape) {
  #app { padding-top: 16px; padding-bottom: 40px; }
  .masthead { margin-bottom: 16px; }
}
