/* THE MAILROOM terminal site — owlcot-family CRT aesthetic.
   Themes: amber (IBM 3270, default) · green (VT100 phosphor) · cyan. */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-deep:   #050709;
  --bg:        #0a0d11;
  --bg-soft:   #0e1217;
  --bg-elev:   #131820;
  --fg:        #d8d4ce;
  --fg-dim:    #6b7585;
  --fg-faint:  #2a303c;
  --amber:     #ffb86c;
  --amber-bright: #ffd09b;
  --phosphor:  #a3e635;
  --cyan:      #67e8f9;
  --magenta:   #f472b6;
  --red:       #ef4444;
  --green:     #4ade80;
  --yellow:    #facc15;
  --border:    #1d2530;
  --sky-1:     #0c130f;
  --sky-2:     #0e1712;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--fg);
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(ellipse 80% 50% at top, rgba(255, 184, 108, 0.05), transparent 70%),
    radial-gradient(ellipse 60% 40% at bottom, rgba(103, 232, 249, 0.025), transparent 70%),
    var(--bg-deep);
}

/* film grain */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.5'/></svg>");
  mix-blend-mode: overlay;
  opacity: 0.06;
}

/* === CRT OVERLAY === */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.4s;
}
.crt-overlay.off { opacity: 0; }
.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.32) 3px,
    rgba(0,0,0,0.32) 4px
  );
  opacity: 0.55;
  animation: scan 6s linear infinite;
}
@keyframes scan {
  0% { transform: translateY(0); }
  100% { transform: translateY(4px); }
}
.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 110% 100% at center, transparent 45%, rgba(0,0,0,0.55) 100%);
}
.flicker {
  position: absolute;
  inset: 0;
  background: rgba(255, 184, 108, 0.018);
  animation: flicker 7s infinite;
}
@keyframes flicker {
  0%, 94%, 100% { opacity: 1; }
  95% { opacity: 0.82; }
  96% { opacity: 1; }
  97% { opacity: 0.93; }
  98% { opacity: 1; }
}

/* === AMBIENT MAILROOM SKYLINE === */
#ambientSkyline {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 30vh;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.6s ease;
  overflow: hidden;
}
#ambientSkyline.off { opacity: 0; }
#ambientSkyline .skyline {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  height: 72%;
  display: block;
}
#ambientSkyline .skyline.back { opacity: 0.55; bottom: -6%; }
.fog {
  position: absolute;
  bottom: -12%;
  width: 70%;
  height: 45%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(20,32,26,0.55), transparent 70%);
  filter: blur(18px);
  animation: fogDrift 90s ease-in-out infinite alternate;
}
.fog.f1 { left: -15%; }
.fog.f2 { right: -20%; animation-duration: 130s; animation-delay: -40s; }
@keyframes fogDrift {
  0%   { transform: translateX(0)    translateY(0); }
  100% { transform: translateX(12%)  translateY(-4%); }
}
.conveyor-dot {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px 1px rgba(255, 184, 108, 0.8);
  opacity: 0;
  animation-name: conveyorFloat, conveyorGlow;
  animation-timing-function: ease-in-out, ease-in-out;
  animation-iteration-count: infinite, infinite;
}
@keyframes conveyorFloat {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(calc(var(--dx) * 0.5), calc(var(--dy) * -0.7)); }
  50%  { transform: translate(var(--dx), var(--dy)); }
  75%  { transform: translate(calc(var(--dx) * 0.3), calc(var(--dy) * 0.6)); }
  100% { transform: translate(0, 0); }
}
@keyframes conveyorGlow {
  0%, 100% { opacity: 0; }
  15% { opacity: 0.9; }
  45% { opacity: 0.35; }
  60% { opacity: 0.85; }
  80% { opacity: 0.15; }
}

/* === STATUS BAR === */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 14px;
  background: linear-gradient(to bottom, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-dim);
  flex-shrink: 0;
  user-select: none;
  letter-spacing: 0.02em;
  position: relative;
  z-index: 3;
}
.status-group { display: flex; gap: 16px; align-items: center; }
.status-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.status-item b { color: var(--amber); font-weight: 500; }
.status-item a.sister-link {
  color: var(--amber);
  text-decoration: none;
  border-bottom: 1px dotted rgba(255, 184, 108, 0.5);
  padding-bottom: 1px;
  transition: color 0.15s, text-shadow 0.15s;
}
.status-item a.sister-link:hover {
  color: var(--amber-bright);
  text-shadow: 0 0 8px rgba(255, 184, 108, 0.6);
  border-bottom-color: var(--amber-bright);
}
.status-item .dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 7px var(--green);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* === TERMINAL === */
.terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 18px;
  position: relative;
  overflow: hidden;
  z-index: 2;
  transform-origin: 50% 50%;
  animation: crtOn 0.55s ease-out;
}
@keyframes crtOn {
  0%   { transform: scaleY(0.004) scaleX(1.15); filter: brightness(6) saturate(2); opacity: 0.4; }
  55%  { transform: scaleY(1.02) scaleX(1); filter: brightness(1.6); opacity: 1; }
  100% { transform: none; filter: none; opacity: 1; }
}
.output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  padding-bottom: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.output::-webkit-scrollbar { width: 6px; }
.output::-webkit-scrollbar-track { background: transparent; }
.output::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.output::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }
.output:focus { outline: none; }
.line {
  margin-bottom: 2px;
  word-break: break-word;
  white-space: pre-wrap;
  animation: lineIn 0.16s ease-out both;
}
@keyframes lineIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* CRT sweep used on clear */
.crt-sweep {
  position: absolute;
  left: 0; right: 0;
  height: 18%;
  top: -20%;
  background: linear-gradient(180deg, transparent, rgba(255,184,108,0.09), transparent);
  animation: sweepDown 0.45s linear forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes sweepDown {
  from { top: -20%; }
  to   { top: 105%; }
}

/* === PROMPT === */
.prompt-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--bg-soft);
  position: relative;
  flex-shrink: 0;
}
.prompt {
  color: var(--green);
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.45);
  font-weight: 500;
  flex-shrink: 0;
  user-select: none;
}
.prompt .path {
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(103, 232, 249, 0.4);
}
.prompt.compose { color: var(--magenta); text-shadow: 0 0 8px rgba(244, 114, 182, 0.5); }
.input-area { position: relative; flex: 1; min-width: 0; }
.input-display { pointer-events: none; color: var(--fg); }
.ghost-text {
  color: var(--fg-dim);
  opacity: 0.55;
  animation: ghostFlicker 1.06s steps(2, end) infinite;
}
@keyframes ghostFlicker {
  0%, 60% { opacity: 0.55; }
  61%, 100% { opacity: 0.32; }
}
.block-cursor {
  display: inline-block;
  width: 8px;
  height: 17px;
  background: var(--amber);
  vertical-align: text-bottom;
  box-shadow: 0 0 8px var(--amber);
  /* CRT-accurate: blink at 1.06s intervals, steps(2, end) */
  animation: blink 1.06s steps(2, end) infinite;
  margin-left: 1px;
  margin-right: 1px;
}
@keyframes blink {
  0%, 49.999% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
#cmdInput {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
  font: inherit;
  /* iOS zooms on focus for inputs below 16px — this input is invisible,
     so the size only affects that zoom behavior. */
  font-size: 16px;
  z-index: 2;
  cursor: text;
  padding: 0;
}

/* === TEXT === */
.error { color: var(--red); text-shadow: 0 0 5px rgba(239, 68, 68, 0.4); }
.success { color: var(--green); }
.info, .cyan { color: var(--cyan); }
.warn, .yellow { color: var(--yellow); }
.dim { color: var(--fg-dim); }
.amber { color: var(--amber); }
.magenta { color: var(--magenta); }
.phosphor { color: var(--phosphor); }
.cmd-echo { color: var(--fg); }
.shake { animation: shake 0.3s ease-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

/* === MARKDOWN (cat output) === */
.post { margin: 8px 0 14px; }
.post h1, .post h2, .post h3 {
  color: var(--amber);
  font-weight: 600;
  text-shadow: 0 0 10px rgba(255, 184, 108, 0.4);
  line-height: 1.3;
  margin: 18px 0 8px;
}
.post h1 {
  font-size: 1.5em;
  letter-spacing: -0.01em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.post h2 { font-size: 1.2em; }
.post h3 { font-size: 1.05em; color: var(--amber-bright); }
.post p { margin: 8px 0; color: var(--fg); }
.post em { color: var(--fg); font-style: italic; opacity: 0.85; }
.post strong { color: var(--amber-bright); font-weight: 600; }
.post code {
  color: var(--phosphor);
  background: rgba(163, 230, 53, 0.08);
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 0.95em;
  border: 1px solid rgba(163, 230, 53, 0.18);
}
.post pre {
  margin: 10px 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 10px 12px;
  overflow-x: auto;
}
.post pre code {
  display: block;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 0.95em;
  line-height: 1.5;
}
.post a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(103, 232, 249, 0.4);
  transition: color 0.15s, text-decoration-color 0.15s;
}
.post a:hover { color: var(--magenta); text-decoration-color: var(--magenta); }
.post blockquote {
  border-left: 2px solid var(--amber);
  padding: 6px 0 6px 14px;
  margin: 12px 0;
  color: var(--fg-dim);
  font-style: italic;
  background: rgba(255, 184, 108, 0.04);
}
.post ul, .post ol { padding-left: 22px; margin: 8px 0; }
.post li { margin: 3px 0; }
.post ul li::marker, .post ol li::marker { color: var(--amber); }
.divider { color: var(--fg-faint); margin: 8px 0; overflow: hidden; }
.post-footer { margin-top: 10px; color: var(--fg-dim); }
.post-footer a { color: var(--cyan); }
table.mr {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.92em;
}
table.mr th, table.mr td {
  border: 1px solid var(--border);
  padding: 3px 10px;
  text-align: left;
  vertical-align: top;
}
table.mr th { color: var(--amber); font-weight: 600; }
table.mr tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* === LISTING (ls) === */
.listing {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
  margin: 4px 0;
  line-height: 1.7;
}
.file { color: var(--fg); }
.file.dir { color: var(--cyan); font-weight: 500; }
.file.dir::after { content: '/'; opacity: 0.7; }
.file.md { color: var(--amber); }
.file.hidden { color: var(--fg-dim); }

/* === MAN PAGE === */
.man-page {
  border: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(255,184,108,0.025), rgba(255,184,108,0.005));
  padding: 10px 14px;
  margin: 8px 0;
  border-radius: 2px;
  box-shadow: inset 0 0 30px rgba(255, 184, 108, 0.03);
}
.man-page pre { font: inherit; white-space: pre-wrap; color: var(--fg); }

/* === BOOT === */
.boot-line { color: var(--fg-dim); font-size: 0.95em; }
.boot-line .ok { color: var(--green); font-weight: 500; }
.boot-line .warn { color: var(--yellow); font-weight: 500; }
.neofetch { color: var(--fg); line-height: 1.3; margin: 6px 0; }
.lore-line { color: var(--fg-dim); }
.motd {
  margin: 8px 0 6px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--amber);
  background: linear-gradient(180deg, rgba(255,184,108,0.04), transparent);
  padding: 10px 14px;
  border-radius: 2px;
}
.motd p { margin: 2px 0; }
.title-card { margin: 6px 0 4px; overflow-x: auto; }
.title-card pre {
  font: inherit;
  line-height: 1.15;
  display: inline-block;
  color: var(--fg);
}
.banner {
  color: var(--amber);
  text-shadow: 0 0 14px rgba(255, 184, 108, 0.35);
  animation: bannerIn 0.9s ease-out both;
}
@keyframes bannerIn {
  0% { opacity: 0; filter: brightness(3); }
  100% { opacity: 1; filter: brightness(1); }
}
.envelope-art { color: var(--fg); display: inline-block; }
.envelope-art .flap {
  display: inline-block;
  color: var(--amber);
  text-shadow: 0 0 8px rgba(255, 184, 108, 0.75);
  animation: flapBob 4.6s ease-in-out infinite;
}
@keyframes flapBob {
  0%, 91%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.08); }
  97% { transform: scaleY(1); }
}
.hop-in { animation: hopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes hopIn {
  0%   { transform: translateY(-16px); opacity: 0; }
  70%  { transform: translateY(2px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

body.theme-flash .terminal { animation: themeFlash 0.35s ease-out; }
@keyframes themeFlash {
  0% { filter: brightness(1.7) saturate(1.3); }
  100% { filter: none; }
}

/* === RUN STORY / INSPECT === */
.run-story { margin: 8px 0 14px; }
.run-story h1 {
  color: var(--amber);
  font-size: 1.35em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.run-story .kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 18px; margin: 8px 0; }
.run-story .kv b { color: var(--fg-dim); font-weight: 500; }
.run-story .kv span { color: var(--fg); }
.run-story .stage-line { margin: 3px 0; }
.run-story .stage-line .st { color: var(--cyan); font-weight: 500; }

/* === MAIL === */
.mail-form { border: 1px dashed var(--border); padding: 8px 12px; margin: 6px 0; }
.mail-form .field { margin: 6px 0; }
.mail-form .field b { color: var(--fg-dim); font-weight: 500; }
.mail-form .field span { color: var(--fg); }
.mail-summary {
  border: 1px solid var(--border);
  padding: 10px 14px;
  margin: 8px 0;
  background: rgba(74,222,128,0.04);
}
.mail-summary a { color: var(--cyan); }

/* === SELECTION === */
::selection { background: rgba(255, 184, 108, 0.32); color: var(--amber-bright); }

/* === MOBILE === */
@media (max-width: 640px) {
  html { font-size: 12px; }
  .terminal { padding: 10px; }
  .status-bar { font-size: 10px; padding: 4px 10px; }
  .status-group { gap: 10px; }
  .status-item:not(.essential) { display: none; }
  .block-cursor { width: 7px; height: 15px; }
  #ambientSkyline { height: 22vh; }
}

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