/* =========================
   Neo-brutalist design tokens
   ========================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root{
  /* Tide blue colour way */
  --blue:#005CE3;
  --blue-dark:#0047B0;
  --blue-pale:#DCE9FF;

  --ink:#0B0B0F;          /* borders + headline text */
  --dim:#3F4650;
  --paper:#FFFFFF;
  --bg:#EDF3FE;           /* flat page field */
  --danger:#E5484D;
  --danger-pale:#FFE1E1;
  --success:#17B26A;
  --success-pale:#D9F6E8;
  --warn-pale:#FFE8C2;
  --warn-ink:#7A4A00;

  --bw:3px;               /* signature border width */
  --r:10px;
  --r-sm:8px;

  /* hard offset shadows - no blur, ever */
  --shadow-sm:3px 3px 0 var(--ink);
  --shadow:6px 6px 0 var(--ink);
  --shadow-lg:10px 10px 0 var(--ink);
  --shadow-blue:4px 4px 0 var(--blue);

  /* Modal sizing */
  --modal-w:600px;
  --modal-pad:28px;
  --modal-gap:16px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  /* flat field with a dot grid - no photos, no gradients */
  background-image: radial-gradient(circle, rgba(0,92,227,.22) 1.4px, transparent 1.5px);
  background-size: 26px 26px;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; position: relative; overflow-x: hidden;
  color: var(--ink);
}

/* =========================
   Home Card
   ========================= */
.container {
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 500px;
  width: 100%;
  position: relative; z-index: 1;
}

/* =========================
   Brand header
   ========================= */
.brand{
  display:flex;
  align-items: baseline;
  justify-content:center;
  gap:14px;
  margin-bottom:28px;
}
.brand-logo{
  width: clamp(68px, 9.5vw, 96px);
  height:auto;
  display:block;
  align-self: baseline;
  transform: translateY(-2px);
}
.brand-title{
  font-size: clamp(30px, 2.2vw + 20px, 46px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.0;
  margin: 0;
  color: var(--ink);
  text-transform: uppercase;
  text-rendering: optimizeLegibility;
}

/* =========================
   Primary Button on home
   ========================= */
.button {
  background: var(--blue);
  color:#fff;
  border: var(--bw) solid var(--ink);
  padding:18px 22px;
  border-radius: var(--r-sm);
  font-size:16px; font-weight:800; text-transform: uppercase; letter-spacing:.02em;
  cursor:pointer; width:100%;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: transform .1s ease, box-shadow .1s ease;
}
.button:hover{ transform: translate(-2px,-2px); box-shadow: 8px 8px 0 var(--ink); }
.button:active{ transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.button:disabled{
  background:#9CA3AF; color:#f3f4f6; cursor:not-allowed;
  transform:none; box-shadow: var(--shadow-sm);
}

/* =========================
   Generic Buttons (.btn)
   ========================= */
.btn {
  appearance:none;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  padding:12px 16px; font-size:15px; font-weight:800;
  cursor:pointer; width:auto; margin-bottom:0;
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .1s ease, opacity .1s ease;
  min-height: 44px;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity:.65; cursor:not-allowed; transform:none; box-shadow: var(--shadow-sm); }
.btn-primary { background: var(--blue); color:#fff; }
.btn-ghost { background: var(--paper); color: var(--ink); }
.btn-ghost:hover { background: var(--blue-pale); }
.btn:focus-visible, .button:focus-visible {
  outline: var(--bw) solid var(--blue);
  outline-offset: 2px;
}

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner{
  display:inline-block; width:18px; height:18px;
  border:3px solid rgba(255,255,255,.4); border-right-color:#fff;
  border-radius:50%; animation: spin .8s linear infinite;
  vertical-align:-3px; margin-right:8px;
}
.btn-ghost .spinner{ border-color: rgba(11,11,15,.25); border-right-color: var(--ink); }
.spinner-label{ vertical-align:middle; }

/* =========================
   Status Banner
   ========================= */
.status {
  margin-top: 16px; padding: 14px;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  font-size: 14px; font-weight: 800;
}
.status.info { background: var(--blue-pale); color: var(--ink); }
.status.success { background: var(--success-pale); color: var(--ink); }
.status.error { background: var(--danger-pale); color: var(--ink); }

.hidden { display:none !important; }
input[type="file"] { display:none; }

/* =========================
   Modal System
   ========================= */
.modal-backdrop{
  position:fixed; inset:0;
  background: rgba(0,71,176,.35);
  display:flex; align-items:center; justify-content:center;
  z-index:1100;
}
.modal-card{
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r);
  padding: var(--modal-pad);
  width: min(var(--modal-w), calc(100% - 32px));
  max-height: min(86vh, 760px);
  overflow:auto;
  box-shadow: var(--shadow-lg);
  text-align:left;
  display:flex; flex-direction:column; gap: var(--modal-gap);
  line-height: 1.55;
  animation: modalIn .12s ease-out;
}
@keyframes modalIn { from{ opacity:0; transform: translate(4px,4px); } to{ opacity:1; transform: translate(0,0); } }

.modal-header{ display:flex; align-items:center; gap:12px; margin-bottom:2px; }
.avatar{
  width:40px; height:40px;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  display:grid; place-items:center; font-weight:900; color:#fff;
  background: var(--blue);
  box-shadow: var(--shadow-sm);
}
.modal-title{ font-size:22px; font-weight:900; color:var(--ink); margin:0; letter-spacing:-0.02em; }
.sub{ color:var(--dim); font-size:13px; font-weight:600; }

/* Body copy */
.modal-intro, .modal-description{ color:var(--dim); line-height:1.7; font-size:16px; }

/* Alignment modes */
.modal-card.align-center,
.modal-card.align-title-actions,
.modal-card.center { text-align:center; }
.modal-card.align-center .modal-header,
.modal-card.align-title-actions .modal-header,
.modal-card.center .modal-header { justify-content:center; }
.modal-card.align-center .modal-title,
.modal-card.align-center .modal-intro,
.modal-card.align-title-actions .modal-title,
.modal-card.align-title-actions .modal-intro,
.modal-card.center .modal-title,
.modal-card.center .modal-intro { text-align:center; margin-left:auto; margin-right:auto; }

/* Keep long blocks readable even when centered */
.modal-card.align-center .field,
.modal-card.align-center .kv,
.modal-card.align-center .error-details pre,
.modal-card.center .field,
.modal-card.center .kv,
.modal-card.center .error-details pre { text-align:left; margin-left:auto; margin-right:auto; max-width:520px; }

/* Actions */
.modal-actions{ display:flex; gap:12px; justify-content:center; margin-top:8px; }
.modal-card .btn{ width:auto; margin-bottom:0; padding:11px 16px; min-width:112px; }

/* Key/value preview */
.kv{
  display:grid; grid-template-columns:140px 1fr; gap:10px 14px; align-items:baseline;
  background: var(--blue-pale);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm); padding:12px;
}
.kv-k{ color:var(--dim); font-weight:800; font-size:13px; text-transform: uppercase; letter-spacing:.03em; }
.kv-v{ color:var(--ink); word-break: break-word; font-weight:600; }

/* =========================
   Consistent slim pages
   ========================= */
.modal-body{
  display:flex;
  flex-direction:column;
  gap: 12px;
  min-block-size: 280px;
}
.modal-spacer{ flex:1 1 auto; }

/* Domain card */
.domain-card{
  display:grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  align-items:center;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.domain-label{
  color:var(--dim);
  font-weight:800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing:.03em;
}
.domain-value{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 18px;
  color: var(--ink);
  background: var(--blue-pale);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  word-break: break-word;
}

/* =========================
   Welcome Steps (boxed)
   ========================= */
.steps-card{
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-left: 10px solid var(--blue);
  border-radius: var(--r-sm);
  padding:16px 18px;
  box-shadow: var(--shadow-sm);
  margin: 10px auto 6px;
  max-width: 520px;
}
.steps-card__header{
  display:flex; align-items:center; gap:10px; margin-bottom:8px;
}
.steps-card__icon{ width:18px; height:18px; color: var(--blue); }
.steps-card__title{
  font-weight:900; color: var(--ink);
  letter-spacing: -0.01em;
}
.steps-list{
  list-style: decimal;
  list-style-position: outside;
  padding-left: 24px;
  margin: 0;
  color: var(--dim);
  line-height: 1.65;
  text-align: left; /* numbered steps stay readable inside centered modals */
}
.steps-list li{ margin: 6px 0; }

/* Compatibility: legacy .info-steps */
.info-steps{ list-style: decimal; padding-left:24px; margin:0; color:var(--dim); line-height:1.65; }
.info-steps li{ margin:6px 0; }

.modal-note{
  color: var(--dim);
  font-size: 14px;
  margin-top: 6px;
  text-align: center;
}

/* Rhythm */
.wizard-step{ display:grid; gap: 12px; }

/* =========================
   Form Fields
   ========================= */
.field-set{ display:flex; flex-direction:column; gap:16px; max-width:520px; }
.field{ display:grid; gap:8px; margin: 6px 0; }
.field-label{ font-weight:800; color:var(--ink); font-size:13px; text-transform: uppercase; letter-spacing:.03em; }
.input{
  -webkit-appearance:none; appearance:none;
  width:100%; padding:14px 14px;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--paper);
  font-size:16px; color:var(--ink); font-weight:600;
  outline:none;
  transition: box-shadow .1s ease, transform .1s ease;
  min-height: 44px; line-height: 1.25; /* mobile-friendly */
}
.input:focus{ box-shadow: var(--shadow-blue); transform: translate(-1px,-1px); }
.input::placeholder{ color:#9CA3AF; font-weight:500; }
.field-hint{ color: var(--dim); font-size:13px; min-height: 1.2em; }

/* Section titles */
.section-title{
  font-weight:900; color:var(--ink);
  margin: 4px 0 4px;
  letter-spacing: -0.01em;
}

/* Readonly / Disabled */
.input[readonly], .input:read-only{
  background: var(--bg);
  color: var(--dim);
  cursor: default;
}
.input[disabled]{
  background:#E5E7EB;
  color:#6B7280;
  cursor: not-allowed;
}

/* Readonly username + optional link */
.readonly-field{ display:grid; gap:6px; }
.pill{
  display:inline-flex; align-items:center; gap:8px; width:fit-content;
  padding:8px 14px; border-radius:999px;
  background: var(--blue-pale);
  border: var(--bw) solid var(--ink);
  color: var(--ink); font-weight:800;
  box-shadow: var(--shadow-sm);
}
.link-btn{
  appearance:none; border:0; background:transparent; padding:0;
  color: var(--blue); font-weight:800; cursor:pointer;
  text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset:3px;
}
.link-btn:focus-visible{ outline: var(--bw) solid var(--blue); outline-offset:2px; border-radius: 4px; }

/* Warn / Acknowledgement */
.warn-card{
  background: var(--warn-pale); color: var(--warn-ink);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-sm);
  padding:12px;
  box-shadow: var(--shadow-sm);
  font-weight:600;
}
.ack-row{
  display:flex; gap:10px; align-items:flex-start;
  font-size:14px; color:var(--dim); text-align:left; margin: 8px 0 12px;
}

/* Error details */
.error-details summary{ cursor:pointer; color:var(--ink); font-weight:700; }
.error-details pre{
  background: var(--ink); color:#E5E7EB;
  border: var(--bw) solid var(--ink); border-radius: var(--r-sm);
  padding:12px; max-height:220px; overflow:auto; margin-top:8px;
}

/* =========================
   Floating Restart (FAB)
   ========================= */
.floating-restart{
  /* Laid out BY .tide-overlay (a flex column) - app.js moves this button in
     there. Must not be position:fixed, or it leaves the flex flow and lands
     on top of the Settings FAB instead of stacking above it. */
  position: static;
  background: var(--paper); color: var(--ink);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding:10px 16px; border-radius:999px; font-weight:800;
}
.floating-restart.hidden{ display:none !important; }
body.has-modal .floating-restart{ display:none !important; }
body.has-modal{ overflow:hidden; }

/* =========================
   Toasts (safe-area aware)
   ========================= */
/* Toasts live in their own stack on the BOTTOM-LEFT, so they never collide
   with the FAB column on the right, and multiple toasts queue instead of
   rendering on top of each other. */
.toast-stack{
  position: fixed;
  left: 16px;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 1200;
  display: flex;
  flex-direction: column-reverse; /* newest nearest the bottom */
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--paper); color: var(--ink);
  border: var(--bw) solid var(--ink);
  border-left: 10px solid var(--blue);
  border-radius: var(--r-sm); padding:12px 14px; font-weight:800; font-size:14px;
  text-align: center;
  box-shadow: var(--shadow);
  opacity:0; transform: translate(-4px,4px);
  animation: toastIn .12s ease forwards;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
@keyframes toastIn { to{ opacity:1; transform: translate(0,0); } }

/* =========================
   Overlay toolbar created by app.js
   ========================= */
.tide-overlay{
  position:fixed;
  right:16px;
  bottom: calc(16px + var(--safe-bottom));
  display:flex;
  flex-direction:column;
  gap:10px;
  z-index:1200;
  pointer-events:none;
}
.tide-fab{
  pointer-events:auto;
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:10px 14px;
  border-radius:999px;
  border: var(--bw) solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight:800;
}
.tide-fab .dot{
  width:10px; height:10px; border-radius:50%;
  background: var(--blue); border:2px solid var(--ink); display:inline-block;
}

/* =========================
   Validation helpers (used by app.js)
   ========================= */
.input.is-invalid {
  border-color: var(--danger);
  background: var(--danger-pale);
}
.input.error{
  border-color: var(--danger);
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--danger);
}
.input.error:focus{
  border-color: var(--danger);
  box-shadow: 4px 4px 0 var(--danger);
}
.field-error{
  color: var(--danger);
  font-size:12px;
  font-weight:800;
  margin-top:4px;
}

/* =========================
   Responsive
   ========================= */
@media (max-width: 480px){
  body{ padding: 14px; }
  .container{ padding: 28px 20px; margin: 8px; max-width: 440px; box-shadow: var(--shadow); }

  .brand { gap: 12px; }
  .brand-logo { transform: translateY(-1px); }
  .brand-title{ font-size: clamp(24px, 7vw, 36px); }

  .modal-card{ width: calc(100% - 24px); padding: 20px 16px; box-shadow: var(--shadow); }
  .kv{ grid-template-columns: 1fr; }
  .domain-card{ grid-template-columns: 1fr; }
  .modal-actions{ flex-wrap: wrap; }
  .modal-card .btn{ flex: 1 1 48%; min-width:auto; }
}

/* Small phones (e.g. iPhone SE, 320-380px) */
@media (max-width: 380px){
  body{ padding: 10px; }
  .container{ padding: 20px 14px; margin: 4px; box-shadow: var(--shadow-sm); }

  /* Stack logo above the title - side by side they clip */
  .brand{ flex-direction: column; align-items: center; gap: 8px; margin-bottom: 20px; }
  .brand-logo{ width: 56px; transform: none; align-self: center; }
  .brand-title{ font-size: clamp(20px, 8.5vw, 28px); letter-spacing: -0.02em; }

  .button{ padding: 15px 16px; font-size: 15px; }

  .modal-card{
    width: calc(100% - 12px);
    padding: 16px 12px;
    box-shadow: var(--shadow-sm);
    --modal-gap: 12px;
  }
  .modal-title{ font-size: 19px; }
  .modal-intro, .modal-description{ font-size: 15px; }
  .modal-body{ min-block-size: 0; }
  .steps-card{ padding: 12px; border-left-width: 6px; }
  .modal-card .btn{ flex: 1 1 100%; padding: 12px 10px; min-width: 0; }

  .domain-value{ font-size: 15px; }
  .kv{ padding: 10px; }

  .tide-fab, .floating-restart{ padding: 8px 12px; font-size: 13px; }
  /* Narrow screens: full width, and lifted clear of the FAB column. */
  .toast-stack{ left: 10px; right: 10px; max-width: none; bottom: calc(72px + var(--safe-bottom)); }
}

/* Short screens (landscape phones, small windows): stop clipping the top */
@media (max-height: 640px){
  body{ align-items: flex-start; overflow-y: auto; }
  .modal-card{ max-height: calc(100dvh - 24px); }
  .modal-body{ min-block-size: 0; }
}

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

/* =========================
   A11y
   ========================= */
.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;
}

/* =========================
   CTA busy/redirect states
   ========================= */
.button.is-busy, .btn.is-busy{
  pointer-events:none; opacity:.95;
}
.button.is-redirecting, .btn.is-redirecting{
  background:#9CA3AF !important;
  box-shadow: var(--shadow-sm) !important;
  transform:none !important;
}
@keyframes pulseFade { 0%{opacity:1} 50%{opacity:.6} 100%{opacity:1} }
.button.is-redirecting .spinner-label,
.btn.is-redirecting .spinner-label{
  animation:pulseFade 1.2s ease-in-out infinite;
}

/* =========================
   Inputs: platform quirks
   ========================= */
/* Hide number spinners just in case */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
