:root {
  --page: #e6e9ee;
  --panel: #ffffff;
  --line: #d3d9e2;
  --ink: #1f2a3a;
  --muted: #5a6577;
  --policy: #2b5c9e;
  --fail: #b3261e;
  --body: #2b2925;        /* machine case */
  --body-edge: #1a1916;
  --metal: #8c8a84;
  --key: #1d1c1a;
  --key-ring: #b9b5aa;
  --lamp-off: #3b3934;
  --lamp-on: #ffd36b;
  --font: "Public Sans", "Segoe UI", Arial, sans-serif;
  --mono: "Share Tech Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font);
}

.portal-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--policy);
  color: #fff;
  font-size: 0.9rem;
}
.portal-name { font-weight: 800; }
.summary { font-family: var(--mono); opacity: 0.9; }

.page {
  max-width: 64rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

h1 {
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}
.lede { color: var(--muted); margin: 0 0 1.5rem; max-width: 44rem; }

/* Settings */
.settings {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
}
.settings-row { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end; }
.settings-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-left: auto; }

.field { display: grid; gap: 0.25rem; font-weight: 600; font-size: 0.9rem; }
.field select, .field input, .field textarea {
  font: 400 1rem var(--font);
  padding: 0.45rem 0.55rem;
  border: 2px solid #9aa5b5;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}
.field select:focus, .field input:focus, .field textarea:focus {
  outline: 3px solid var(--policy);
  outline-offset: 1px;
  border-color: var(--policy);
}
#plugs, #paste { font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }

.slot-settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.slot {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.7rem 0.8rem 0.8rem;
  display: grid;
  gap: 0.5rem;
  background: #f4f6f9;
}
.slot-title { margin: 0; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.plug-field { max-width: 40rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.error { color: var(--fail); font-weight: 600; font-size: 0.85rem; min-height: 1.2em; }

.btn {
  font: 600 0.95rem var(--font);
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 3px;
  background: var(--policy);
  color: #fff;
  cursor: pointer;
}
.btn.secondary { background: #e3ecf8; color: var(--policy); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Machine */
.machine {
  background: var(--body);
  border: 10px solid var(--body-edge);
  border-radius: 12px;
  padding: 1.25rem 1rem 1.5rem;
  display: grid;
  gap: 1.25rem;
  justify-items: center;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25);
}

.windows { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }
.window {
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.6rem 0.5rem;
  background: #3a3833;
  border-radius: 6px;
}
.window-label { color: var(--key-ring); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; }
.window-letter {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.9rem;
  background: #f3efe4;
  color: #1d1c1a;
  border: 3px solid var(--metal);
  border-radius: 4px;
  font: 400 1.7rem var(--mono);
}
.window-letter.turned { animation: turn 0.18s ease-out; }
@keyframes turn { from { transform: translateY(-6px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.window-num { color: var(--key-ring); font: 400 0.75rem var(--mono); }
.turn-btn {
  width: 2.6rem;
  border: 0;
  border-radius: 3px;
  background: #55524b;
  color: #f3efe4;
  font-size: 0.8rem;
  line-height: 1.4;
  cursor: pointer;
}
.turn-btn:focus-visible { outline: 3px solid var(--lamp-on); }

.board { display: grid; gap: 0.55rem; justify-items: center; width: 100%; }
.board-row { display: flex; gap: 0.5rem; justify-content: center; }

.lamp {
  display: grid;
  place-items: center;
  width: clamp(1.9rem, 6.5vw, 2.8rem);
  height: clamp(1.9rem, 6.5vw, 2.8rem);
  border-radius: 50%;
  background: var(--lamp-off);
  border: 2px solid #4a4741;
  color: #8f8b82;
  font: 400 clamp(0.9rem, 2.6vw, 1.2rem) var(--mono);
  transition: background 0.05s, color 0.05s, box-shadow 0.05s;
}
.lamp.on {
  background: var(--lamp-on);
  color: #3a2a00;
  box-shadow: 0 0 18px 6px rgba(255, 211, 107, 0.65);
}

.keys { padding-top: 1rem; border-top: 2px solid #3a3833; }
.key {
  width: clamp(1.9rem, 6.5vw, 2.8rem);
  height: clamp(1.9rem, 6.5vw, 2.8rem);
  border-radius: 50%;
  border: 3px solid var(--key-ring);
  background: var(--key);
  color: #f3efe4;
  font: 400 clamp(0.9rem, 2.6vw, 1.2rem) var(--mono);
  cursor: pointer;
  box-shadow: 0 4px 0 #0c0b0a;
  touch-action: manipulation;
}
.key.down { transform: translateY(3px); box-shadow: 0 1px 0 #0c0b0a; }
.key:focus-visible { outline: 3px solid var(--lamp-on); outline-offset: 2px; }

/* Tape */
.tape {
  margin-top: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.25rem 1.25rem;
}
.tape-row { display: grid; grid-template-columns: 4.5rem 1fr; gap: 0.75rem; align-items: start; margin-bottom: 0.5rem; }
.tape-label { font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding-top: 0.3rem; }
.tape-text {
  min-height: 2.2rem;
  padding: 0.3rem 0.6rem;
  background: #f4f6f9;
  border: 1px solid var(--line);
  border-radius: 3px;
  font: 400 1.15rem var(--mono);
  letter-spacing: 0.1em;
  word-break: break-word;
}
.tape-text.out { color: var(--policy); }
.tape-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.25rem 0 1rem; }
.paste-field { margin-bottom: 0.6rem; }

@media (prefers-reduced-motion: reduce) {
  .window-letter.turned { animation: none; }
  .lamp { transition: none; }
}
