:root {
  color-scheme: dark;
  --ink: #f8ecd8;
  --muted: #cbbba8;
  --wine: #6d2941;
  --wine-bright: #9d4664;
  --gold: #dab77a;
  --panel: rgba(31, 17, 25, 0.92);
  --line: rgba(218, 183, 122, 0.28);
  font-family: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #120b10; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(138, 55, 84, 0.24), transparent 30rem),
    radial-gradient(circle at 85% 80%, rgba(196, 139, 76, 0.12), transparent 35rem),
    linear-gradient(145deg, #120b10, #24131c 52%, #100a0e);
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.portal-page::before,
.portal-page::after {
  content: '';
  position: fixed;
  width: 18rem;
  height: 18rem;
  border: 1px solid rgba(218, 183, 122, 0.1);
  border-radius: 50%;
  pointer-events: none;
}
.portal-page::before { top: -10rem; right: -7rem; }
.portal-page::after { bottom: -12rem; left: -7rem; }

.portal-shell {
  width: min(100% - 2rem, 31rem);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 2rem 0;
}

.portal-shell--wide { width: min(100% - 2rem, 76rem); }

.portal-card,
.admin-board {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--panel);
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(12px);
}

.portal-card { padding: clamp(1.5rem, 5vw, 2.75rem); text-align: center; }
.portal-mark { color: var(--gold); font-size: 2.25rem; line-height: 1; }
.portal-eyebrow {
  margin: 1rem 0 0.45rem;
  color: var(--gold);
  font: 600 0.75rem/1.4 system-ui, sans-serif;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; font-weight: 500; }
h1 { font-size: clamp(2rem, 8vw, 3.25rem); line-height: 1.05; }
.portal-intro { margin: 0.8rem 0 1.5rem; color: var(--muted); line-height: 1.6; }

.portal-form { display: grid; gap: 0.65rem; text-align: left; }
.portal-form label,
.admin-slot-form label { color: var(--muted); font: 600 0.82rem/1.4 system-ui, sans-serif; }

.portal-form input,
.admin-slot-form input[type='file'] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.8rem 0.9rem;
  color: var(--ink);
  background: rgba(8, 5, 7, 0.55);
}

.portal-form button,
.portal-button-link,
.portal-button-secondary,
.admin-slot-actions button {
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.portal-form button,
.portal-button-link,
.admin-slot-actions button[type='submit'] {
  color: #fff8ec;
  background: linear-gradient(135deg, var(--wine), var(--wine-bright));
}
.portal-form button { margin-top: 0.6rem; }
.portal-button-secondary,
.admin-slot-actions .danger-button {
  color: var(--ink);
  border-color: var(--line);
  background: transparent;
}
.admin-slot-actions .danger-button { color: #f3b7bf; }

button:hover:not(:disabled),
.portal-button-link:hover { transform: translateY(-1px); }
button:disabled { cursor: wait; opacity: 0.58; }

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(218, 183, 122, 0.7);
  outline-offset: 3px;
}

.portal-status { min-height: 1.5rem; margin: 1rem 0 0; color: #e9c3b2; line-height: 1.45; }
.portal-admin-link { display: inline-block; margin-top: 1rem; color: var(--muted); font-size: 0.84rem; }

.admin-board { padding: clamp(1rem, 3vw, 2rem); }
.admin-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; }
.admin-header .portal-intro { margin-bottom: 0; }
.admin-header-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.admin-global-status { text-align: left; }
.admin-slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.admin-slot-card {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(9, 6, 8, 0.38);
}
.admin-slot-card h2 { margin-bottom: 0.7rem; color: var(--gold); font-size: 1.1rem; }
.admin-slot-preview {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0.75rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
  text-align: center;
}
.admin-slot-preview img { width: 100%; height: 100%; object-fit: cover; }
.admin-slot-preview span { padding: 1rem; font-size: 0.88rem; line-height: 1.4; }
.admin-slot-form { display: grid; gap: 0.6rem; margin-top: 0.8rem; }
.admin-slot-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }
.admin-slot-status { min-height: 2.6em; margin: 0.7rem 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.35; }

[hidden] { display: none !important; }

@media (max-width: 42rem) {
  .portal-shell { width: min(100% - 1rem, 31rem); padding: 0.5rem 0; }
  .portal-shell--wide { width: min(100% - 1rem, 76rem); }
  .portal-card, .admin-board { border-radius: 0.9rem; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .admin-header-actions { width: 100%; }
  .admin-header-actions > * { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   Firewall Breach - the gate only.
   Everything below is scoped to .portal-page--unlock so admin.html keeps the
   original wine-and-gold portal styling.
   ============================================================ */

.portal-page--unlock {
  --term: #58ff9d;
  --term-dim: #2f8f5c;
  --term-deep: #0a1a12;
  --term-ink: #d6ffe8;
  --term-warn: #ff8f6b;
  font-family: ui-monospace, 'Cascadia Mono', Consolas, 'SF Mono', monospace;
  color: var(--term-ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(60, 255, 157, 0.09), transparent 28rem),
    radial-gradient(circle at 82% 84%, rgba(30, 150, 95, 0.08), transparent 32rem),
    linear-gradient(150deg, #060d0a, #08150f 55%, #050a08);
}

/* The decorative rings from the romantic theme would read as smudges here. */
.portal-page--unlock::before,
.portal-page--unlock::after { display: none; }

.portal-page--unlock .portal-shell { width: min(100% - 2rem, 40rem); }

.breach-scanlines {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(88, 255, 157, 0.035) 0 1px,
    transparent 1px 3px
  );
  animation: breach-scan-drift 9s linear infinite;
}

@keyframes breach-scan-drift {
  to { transform: translateY(3px); }
}

.breach-card {
  position: relative;
  z-index: 1;
  border-color: rgba(88, 255, 157, 0.26);
  border-radius: 0.5rem;
  background: rgba(6, 16, 11, 0.92);
  box-shadow:
    0 1.5rem 5rem rgba(0, 0, 0, 0.6),
    0 0 3rem rgba(40, 200, 120, 0.07),
    inset 0 0 4rem rgba(30, 120, 80, 0.06);
  text-align: left;
}

/* ------------------------------------------------------------- heading --- */

.breach-head { display: grid; gap: 0.35rem; }

.breach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  justify-self: start;
  padding: 0.2rem 0.6rem;
  border: 1px solid rgba(88, 255, 157, 0.3);
  border-radius: 0.25rem;
  color: var(--term);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.breach-chip-dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--term);
  box-shadow: 0 0 0.5rem var(--term);
  animation: breach-blink 1.7s steps(1, end) infinite;
}

@keyframes breach-blink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0.25; }
}

.portal-page--unlock .breach-eyebrow {
  margin: 0.5rem 0 0;
  color: var(--term-dim);
  font-family: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
}

.breach-title {
  color: var(--term-ink);
  font-family: inherit;
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-shadow: 0 0 1.6rem rgba(88, 255, 157, 0.22);
}

.breach-subtitle {
  margin: 1.6rem 0 0.3rem;
  color: var(--term);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.breach-hint {
  margin: 0 0 1rem;
  color: var(--term-ink);
  font-size: 0.92rem;
  line-height: 1.5;
  opacity: 0.85;
}

.breach-hint::before { content: '// '; color: var(--term-dim); }

/* ------------------------------------------------------------- console --- */

.breach-console {
  border: 1px solid rgba(88, 255, 157, 0.2);
  border-radius: 0.35rem;
  background: linear-gradient(180deg, rgba(4, 12, 8, 0.9), rgba(6, 20, 13, 0.9));
  overflow: hidden;
}

.breach-field {
  position: relative;
  height: clamp(15rem, 46vh, 21rem);
  overflow: hidden;
}

.breach-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(88, 255, 157, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(88, 255, 157, 0.05) 1px, transparent 1px);
  background-size: 2rem 2rem;
}

/* The band's top/bottom MUST match BAND_TOP and BAND_BOTTOM in breach.js,
   otherwise the visible target and the hit test disagree. */
.breach-band {
  position: absolute;
  top: 8%;
  bottom: 67%;
  left: 0;
  right: 0;
  border-top: 1px solid rgba(88, 255, 157, 0.55);
  border-bottom: 1px solid rgba(88, 255, 157, 0.55);
  background: linear-gradient(
    180deg,
    rgba(88, 255, 157, 0.14),
    rgba(88, 255, 157, 0.05) 45%,
    rgba(88, 255, 157, 0.14)
  );
  box-shadow: 0 0 1.6rem rgba(88, 255, 157, 0.18);
}

.breach-band-label {
  position: absolute;
  right: 0.5rem;
  bottom: 0.15rem;
  color: rgba(88, 255, 157, 0.65);
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------- glyphs --- */

.breach-glyph {
  position: absolute;
  top: 100%;
  min-height: 0;
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  border: 1px solid rgba(88, 255, 157, 0.25);
  border-radius: 0.3rem;
  color: rgba(214, 255, 232, 0.62);
  background: rgba(8, 24, 16, 0.75);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transform: translate(-50%, -50%);
  /* --rise is set by breach.js so the visual travel matches its hit test. */
  animation: breach-rise var(--rise, 1.5s) linear forwards;
  transition: color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

@keyframes breach-rise {
  from { top: 100%; }
  to { top: -10%; }
}

/* Only meaningful while inside the band, which is the whole game. */
.breach-glyph.is-live {
  color: #eafff3;
  border-color: var(--term);
  background: rgba(20, 70, 46, 0.85);
  box-shadow: 0 0 0.9rem rgba(88, 255, 157, 0.5), inset 0 0 0.7rem rgba(88, 255, 157, 0.2);
}

.breach-glyph.is-captured {
  animation: breach-rise var(--rise, 1.5s) linear forwards, breach-pop 240ms ease-out forwards;
}

@keyframes breach-pop {
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.7); }
}

.breach-glyph.is-rejected {
  animation: breach-rise var(--rise, 1.5s) linear forwards, breach-reject 240ms ease-out forwards;
  border-color: var(--term-warn);
  color: var(--term-warn);
}

@keyframes breach-reject {
  to { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
}

/* ---------------------------------------------------------------- slots --- */

.breach-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.breach-slot {
  flex: 0 0 auto;
  width: 2rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(88, 255, 157, 0.22);
  border-bottom-color: rgba(88, 255, 157, 0.55);
  border-radius: 0.25rem;
  background: rgba(4, 12, 8, 0.6);
  color: var(--term);
  font-size: 1.05rem;
  font-weight: 600;
}

.breach-slot.is-filled {
  border-color: var(--term);
  background: rgba(20, 70, 46, 0.6);
  box-shadow: 0 0 0.7rem rgba(88, 255, 157, 0.22);
}

/* --------------------------------------------------------------- status --- */

.portal-page--unlock .breach-status {
  min-height: 1.4rem;
  margin: 0.75rem 0 0;
  color: var(--term-dim);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.breach-status.is-error { color: var(--term-warn); }
.breach-status.is-ok { color: var(--term); text-shadow: 0 0 1rem rgba(88, 255, 157, 0.4); }
.breach-status.is-busy { color: var(--term-ink); }

.breach-nudge {
  min-height: 1.2rem;
  margin: 0.3rem 0 0;
  color: rgba(214, 255, 232, 0.5);
  font-size: 0.76rem;
  line-height: 1.45;
}

.breach-nudge.is-urgent { color: var(--term-warn); }

.breach-tip {
  margin: 0.8rem 0 0;
  color: rgba(214, 255, 232, 0.45);
  font-size: 0.72rem;
  line-height: 1.5;
}

.breach-tip::before { content: '> '; color: var(--term-dim); }

/* -------------------------------------------------------------- actions --- */

.breach-actions { display: flex; gap: 0.5rem; margin-top: 0.9rem; }

.portal-page--unlock .breach-button {
  min-height: 2.3rem;
  flex: 1;
  border: 1px solid rgba(88, 255, 157, 0.28);
  border-radius: 0.3rem;
  padding: 0.4rem 0.8rem;
  color: var(--term-ink);
  background: rgba(10, 30, 20, 0.7);
  font-family: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.portal-page--unlock .breach-button:hover:not(:disabled) {
  border-color: var(--term);
  background: rgba(20, 70, 46, 0.7);
}

/* ------------------------------------------------- fallback code form --- */

.breach-fallback { margin-top: 1.5rem; }

/* Collapsed once the game is running; the escape hatch brings it back. */
.breach-card.is-playing .breach-fallback { display: none; }
.breach-card.is-playing.is-code-open .breach-fallback {
  display: block;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(88, 255, 157, 0.16);
}

.portal-page--unlock .breach-intro {
  margin: 0 0 1rem;
  color: rgba(214, 255, 232, 0.72);
  font-size: 0.9rem;
}

.portal-page--unlock .portal-form label {
  color: var(--term-dim);
  font-family: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.portal-page--unlock .portal-form input {
  border-color: rgba(88, 255, 157, 0.24);
  border-radius: 0.3rem;
  background: rgba(4, 12, 8, 0.7);
  color: var(--term-ink);
  font-family: inherit;
  letter-spacing: 0.18em;
}

.portal-page--unlock .portal-form input:focus-visible,
.portal-page--unlock button:focus-visible {
  outline: 2px solid rgba(88, 255, 157, 0.75);
  outline-offset: 2px;
}

.portal-page--unlock .portal-form button {
  border-radius: 0.3rem;
  color: #04120b;
  background: linear-gradient(135deg, var(--term), var(--term-dim));
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.portal-page--unlock .portal-status { color: var(--term-warn); font-size: 0.82rem; }

.breach-escape {
  display: block;
  margin: 1.1rem auto 0;
  border: 0;
  padding: 0.3rem 0.5rem;
  color: var(--term-dim);
  background: none;
  font-family: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.breach-escape:hover { color: var(--term); }

/* ------------------------------------------------------------- granted --- */

.breach-card.is-granted {
  border-color: var(--term);
  box-shadow: 0 0 4rem rgba(88, 255, 157, 0.28), inset 0 0 5rem rgba(40, 200, 120, 0.12);
}

.breach-card.is-granted .breach-console { opacity: 0.35; }

@media (max-width: 30rem) {
  .breach-slot { width: 1.7rem; height: 2.2rem; font-size: 0.95rem; }
  .breach-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .breach-scanlines,
  .breach-chip-dot { animation: none !important; }
  /* The rise must survive: without it a glyph would never reach the band. */
  .breach-glyph { animation: breach-rise var(--rise, 1.5s) linear forwards !important; }
  .breach-glyph.is-captured,
  .breach-glyph.is-rejected { opacity: 0; }
}
