:root {
  --bg: #050805;
  --panel: #0a120a;
  --line: #1f5f2a;
  --fg: #7dff8a;
  --dim: #3f9c4b;
  --other: #ffbf47;
  --other-dim: #a77b2c;
  --error: #ff5f5f;
  --glow: 0 0 6px rgba(125, 255, 138, 0.45);
  --other-glow: 0 0 6px rgba(255, 191, 71, 0.4);
  --font: "Courier New", ui-monospace, Menlo, monospace;
}

/* Admin portal: same look, amber frame so the two windows can't be confused. */
body[data-role="admin"] {
  --line: #7a5a17;
  --bg: #0a0703;
  --panel: #120d05;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--panel) 70%, #1a2a1a) 0%, var(--bg) 75%);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  text-shadow: var(--glow);
}

[hidden] { display: none !important; }

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.25) 2px 3px);
  animation: flicker 6s infinite;
}

@keyframes flicker {
  0%, 97%, 100% { opacity: 1; }
  98% { opacity: 0.85; }
}

.window {
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0 0 1px #000, 0 0 24px color-mix(in srgb, var(--line) 35%, transparent) inset;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px;
  min-height: 30px;
  background: var(--line);
  color: #021;
  text-shadow: none;
  font-weight: bold;
  letter-spacing: 0.08em;
  font-size: 14px;
}
.titlebar > span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body[data-role="admin"] .titlebar { color: #fff3d6; }

button {
  font: inherit;
  font-weight: bold;
  letter-spacing: 0.1em;
  color: var(--bg);
  background: var(--fg);
  border: 0;
  padding: 8px 16px;
  cursor: pointer;
  text-shadow: none;
}
button:hover { background: var(--other); }
button:disabled { opacity: 0.5; cursor: wait; }

input, textarea {
  font: inherit;
  color: var(--fg);
  background: #000;
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-shadow: var(--glow);
  caret-color: var(--fg);
}
input:focus, textarea:focus { outline: 1px solid var(--fg); }

.empty { color: var(--dim); font-style: italic; list-style: none; }

body:not([data-role="admin"]) .admin-only { display: none !important; }

/* --- gate --- */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}
.gate .window { width: min(560px, 100%); }
.gate-body { padding: 20px; }
.logo { margin: 0 0 16px; font-size: clamp(9px, 2.6vw, 15px); line-height: 1.1; overflow: hidden; }
.hint { color: var(--dim); margin: 0 0 16px; }

#gate-form { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
.code-line { display: flex; align-items: center; gap: 8px; }
.code-line input { flex: 1; min-width: 0; letter-spacing: 0.15em; }

.code-boxes { display: flex; justify-content: center; gap: clamp(4px, 1.5vw, 10px); }
.code-boxes input {
  width: clamp(34px, 9vw, 52px);
  height: clamp(46px, 12vw, 64px);
  padding: 0;
  text-align: center;
  font-size: clamp(20px, 5vw, 30px);
  font-weight: bold;
}
.code-boxes input.wide { width: clamp(50px, 13vw, 76px); }
.code-boxes input.filled { border-color: var(--fg); }
.prompt { font-weight: bold; }

.error { color: var(--error); min-height: 1.4em; margin: 12px 0 0; text-shadow: 0 0 6px rgba(255,95,95,.5); }

.shake { animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

/* --- portal --- */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; }
.led {
  width: 8px; height: 8px; border-radius: 50%;
  background: #0f0; box-shadow: 0 0 6px #0f0;
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* thread */

.messages {
  list-style: none;
  margin: 0;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-color: var(--line) transparent;
}

.msg {
  max-width: 80%;
  padding: 4px 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.new { animation: appear 0.25s ease-out; }
.msg .meta { font-size: 12px; text-shadow: none; margin-bottom: 2px; }
.msg .sender { font-weight: bold; letter-spacing: 0.05em; }

.msg.theirs {
  --c: var(--other);
  align-self: flex-start;
  border-left: 3px solid var(--c);
  color: var(--c);
  text-shadow: 0 0 6px color-mix(in srgb, var(--c) 45%, transparent);
}
.msg.theirs .meta { color: color-mix(in srgb, var(--c) 60%, #000); }

.msg.mine {
  align-self: flex-end;
  border-right: 3px solid var(--fg);
  text-align: right;
}
.msg.mine .meta { color: var(--dim); }

@keyframes appear { from { opacity: 0; transform: translateY(4px); } }

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-row label { font-size: 13px; color: var(--dim); text-shadow: none; white-space: nowrap; }
.composer-row input { flex: 1; min-width: 0; color: var(--other); text-shadow: var(--other-glow); }
.composer textarea { flex: 1; resize: none; min-width: 0; }

@media (max-width: 720px) {
  .msg { max-width: 92%; }
}

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

/* --- admin: edit messages --- */

.edit-btn {
  margin-left: 8px;
  padding: 0 6px;
  background: none;
  color: var(--dim);
  font-size: 14px;
  letter-spacing: 0;
  opacity: 0.6;
}
.edit-btn:hover, .edit-btn:focus-visible { background: none; color: var(--other); opacity: 1; }

.msg.editing {
  align-self: stretch;
  max-width: none;
  border: 1px dashed var(--other);
  padding: 10px;
  white-space: normal;
}
.edit-form { display: flex; flex-direction: column; gap: 10px; }
.edit-grid { display: grid; grid-template-columns: 130px 1fr 260px; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--dim); text-shadow: none; letter-spacing: 0.05em; }
.field textarea { resize: vertical; }
.edit-form select, .edit-form input { min-width: 0; width: 100%; }
select {
  font: inherit;
  color: var(--fg);
  background: #000;
  border: 1px solid var(--line);
  padding: 8px 10px;
}
.edit-form input[type="datetime-local"] { color-scheme: dark; }
.edit-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.edit-actions .spacer { flex: 1; }
button.secondary { background: none; color: var(--fg); border: 1px solid var(--line); }
button.secondary:hover { background: color-mix(in srgb, var(--line) 40%, transparent); }
button.danger { background: none; color: var(--error); border: 1px solid var(--error); text-shadow: none; }
button.danger:hover { background: var(--error); color: #000; }

@media (max-width: 720px) {
  .edit-grid { grid-template-columns: 1fr 1fr; }
  .edit-grid .field:last-child { grid-column: 1 / -1; }
}
