:root {
  color-scheme: light;
  --paper: #fbfaf4;
  --ink: #07344f;
  --blue: #0797e3;
  --gold: #ffca18;
  --pink: #ff6e91;
  --surface: #fff;
  --muted: #405765;
  --shadow: #07344f;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #071a28;
  --ink: #dff5ff;
  --blue: #57c7ff;
  --gold: #ffd34d;
  --pink: #ff87a5;
  --surface: #0d2b3d;
  --muted: #d0e7f0;
  --shadow: #020c13;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; color: var(--ink); background: var(--paper); font-family: ui-rounded, "Avenir Next", Avenir, system-ui, sans-serif; }
button, a { color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 4px solid var(--pink); outline-offset: -4px; }

.portal-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); width: 100%; height: 100dvh; background: var(--paper); }
.portal-bar { position: relative; z-index: 2; display: grid; grid-template-columns: auto minmax(180px, 1fr) auto; align-items: stretch; gap: 0; color: #07344f; background: var(--gold); border-bottom: 4px solid #07344f; box-shadow: 0 5px 0 rgb(2 13 20 / 22%); }
.portal-button { min-height: 58px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; appearance: none; padding: 10px 15px; color: #07344f; background: #fbfaf4; border: 0; border-left: 3px solid #07344f; font: 900 13px "Courier New", monospace; text-decoration: none; cursor: pointer; }
.portal-button:hover { background: #fff2c9; }
.portal-button:active { box-shadow: inset 3px 3px 0 rgb(7 52 79 / 28%); }
.portal-button[disabled], .portal-button[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.portal-home { min-width: 154px; color: #fff; background: #07344f; border-left: 0; }
.portal-home:hover { color: #07344f; background: var(--pink); }
.portal-random { background: var(--blue); }
.portal-identity { min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 9px 18px; }
.portal-identity strong { overflow: hidden; font-size: 18px; line-height: 1.1; white-space: nowrap; text-overflow: ellipsis; }
.portal-identity span { overflow: hidden; margin-top: 3px; color: #23485e; font: 800 11px "Courier New", monospace; white-space: nowrap; text-overflow: ellipsis; }
.portal-nav { display: flex; }
.portal-stage { position: relative; min-height: 0; overflow: hidden; background: var(--surface); }
.portal-stage iframe { position: relative; z-index: 1; display: block; width: 100%; height: 100%; border: 0; background: #fff; opacity: 0; transition: opacity .24s ease; }
.is-loaded .portal-stage iframe { opacity: 1; }
.portal-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 30px; color: var(--muted); background-color: var(--paper); background-image: radial-gradient(color-mix(in srgb, var(--blue) 28%, transparent) 1.3px, transparent 1.3px); background-size: 28px 28px; text-align: center; font: 900 13px "Courier New", monospace; }
.portal-loading b { color: var(--blue); font-size: 58px; animation: portal-pulse 1.2s ease-in-out infinite; }
.is-loaded .portal-loading { visibility: hidden; }
.portal-error { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 30px; background: var(--paper); font-weight: 800; }

@keyframes portal-pulse { 50% { transform: scale(1.22) rotate(20deg); } }

@media (max-width: 760px) {
  .portal-bar { grid-template-columns: auto minmax(0, 1fr); }
  .portal-home { min-width: 126px; }
  .portal-identity { padding-inline: 13px; }
  .portal-nav { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 3px solid #07344f; }
  .portal-nav .portal-button:first-child { border-left: 0; }
  .portal-button { min-height: 48px; padding: 8px; }
}

@media (max-width: 420px) {
  .portal-home { min-width: auto; }
  .portal-home span:last-child { font-size: 11px; }
  .portal-identity strong { font-size: 16px; }
  .portal-nav .portal-button span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
