/* ============================================================
   TOWA_OS — a haunted operating system
   bone white on rot black, dried-blood red for warnings
   ============================================================ */

:root {
  --bg: #060606;
  --bone: #cfc9ba;
  --bone-dim: #6f6a5e;
  --red: #b31212;
  --red-bright: #ff2020;
  --ghost: #8b7fb8; /* phosphor violet — same family as the dossier eye */
  --win-bg: #0c0c0b;
  --cursor-default: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18"><path d="M2 1 L2 14 L5.6 10.8 L8 16 L10.4 14.9 L8 9.8 L12.6 9.8 Z" fill="%23cfc9ba" stroke="%23060606"/></svg>') 2 1;
  --cursor-point: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18"><path d="M2 1 L2 14 L5.6 10.8 L8 16 L10.4 14.9 L8 9.8 L12.6 9.8 Z" fill="%23b31212" stroke="%23cfc9ba"/></svg>') 2 1;
  --font-ui: "DotGothic16", monospace;
  --font-mono: "IBM Plex Mono", monospace;
  --font-whisper: "EB Garamond", serif;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }
html { background: #000; }

body {
  background: var(--bg);
  color: var(--bone);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
  cursor: var(--cursor-default), default;
}

button, a, .win-close, .filelist button { cursor: var(--cursor-point), pointer; }

::selection { background: var(--red); color: var(--bone); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--bone); }
a:hover { color: var(--red-bright); }
a:focus-visible, button:focus-visible { outline: 1px dashed var(--red-bright); outline-offset: 2px; }

/* ============ boot ============ */
.boot {
  position: fixed; inset: 0; z-index: 10000;
  background: #000;
  display: grid; place-items: center;
  transition: opacity .4s;
}
.boot.off { opacity: 0; pointer-events: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 26px; }
.boot-logo {
  width: clamp(64px, 10vw, 110px);
  filter: drop-shadow(0 0 18px rgba(207,201,186,.35));
  animation: boot-flicker .18s steps(2, start) infinite;
}
.boot-text {
  font-family: var(--font-ui);
  font-size: clamp(14px, 2.4vw, 22px);
  color: var(--bone);
  white-space: pre-wrap;
  text-align: center;
  animation: boot-flicker .18s steps(2, start) infinite;
}
@keyframes boot-flicker { 50% { opacity: .72; } }
.boot-bar {
  width: min(300px, 62vw);
  height: 12px;
  border: 1px solid var(--bone-dim);
  padding: 2px;
}
.boot-bar i {
  display: block; height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, var(--bone) 0 6px, transparent 6px 9px);
  transition: width .12s steps(2);
}

/* ============ screen tear / glitch flash ============ */
.tear {
  position: fixed; inset: 0; z-index: 9500; pointer-events: none;
  opacity: 0;
}
.tear.hit {
  opacity: 1;
  background:
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(255,255,255,0.08) 7px 9px),
    linear-gradient(rgba(179,18,18,0.12), rgba(179,18,18,0.12));
  filter: invert(1);
  mix-blend-mode: difference;
}
body.shake .desktop { animation: shake .18s steps(2) 2; }
@keyframes shake {
  25% { transform: translate(3px, -2px); }
  75% { transform: translate(-3px, 2px); }
}

/* ============ desktop ============ */
.desktop { position: fixed; inset: 0; overflow: hidden; }

.wall { position: absolute; inset: 0; z-index: 0; background: #000; }
.wall-static {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  opacity: .75;
  filter: saturate(.45) contrast(1.1) brightness(1.05);
  transition: opacity .3s, filter .3s;
}
.wall.surge .wall-static {
  opacity: .95;
  filter: saturate(.45) contrast(1.3) brightness(1.25);
}
.wall-sigil {
  position: absolute; right: 5vw; top: 50%;
  width: min(36vmin, 340px);
  transform: translateY(-54%);
  opacity: .05;
  transition: opacity .3s;
  pointer-events: none;
}
.wall.surge .wall-sigil { opacity: .22; }
.grain {
  position: absolute; inset: -60px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.16'/%3E%3C/svg%3E");
  animation: grain 0.45s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-24px, 14px); }
  50% { transform: translate(18px, -20px); }
  75% { transform: translate(-10px, -12px); }
  100% { transform: translate(0, 0); }
}

/* CRT scanlines + vignette over everything */
.desktop::after {
  content: ""; position: absolute; inset: 0; z-index: 6000; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.6) 100%);
}

/* ============ whispers ============ */
.whispers { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.whisper {
  position: absolute;
  font-family: var(--font-whisper);
  font-style: italic;
  color: rgba(207, 201, 186, 0.38);
  white-space: nowrap;
  animation: whisper-drift var(--dur, 14s) linear forwards;
  text-shadow: 0 0 16px rgba(139, 127, 184, .55);
}
@keyframes whisper-drift {
  0% { transform: translateX(0); opacity: 0; filter: blur(7px); }
  14% { opacity: 1; filter: blur(0.4px); }
  85% { opacity: .8; filter: blur(0.4px); }
  100% { transform: translateX(var(--dx, -320px)); opacity: 0; filter: blur(5px); }
}

/* ============ desktop icons ============ */
.icons {
  position: absolute; top: 22px; left: 18px; z-index: 10;
  display: flex; flex-direction: column; gap: 14px;
}
.icon {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  width: 92px; padding: 8px 4px;
  color: var(--bone);
}
.icon:hover .icon-art {
  background: rgba(179,18,18,.28);
  border-color: var(--red-bright);
  animation: icon-jitter .28s steps(2) infinite;
}
.icon:hover .icon-name { background: var(--red); color: #fff; text-shadow: none; }
@keyframes icon-jitter { 50% { transform: translate(1px, -1px); } }
.icon-art {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  font-size: 24px; line-height: 1;
  border: 1px solid var(--bone-dim);
  background:
    linear-gradient(135deg, transparent calc(100% - 22px), rgba(207,201,186,.14) calc(100% - 21px)),
    repeating-linear-gradient(0deg, rgba(0,0,0,.25) 0 1px, transparent 1px 3px),
    rgba(12,12,11,.72);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
  image-rendering: pixelated;
  transition: transform .12s;
}
.icon:active .icon-art { transform: scale(.93); }
.icon-name {
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 1px 5px;
  color: var(--bone);
  text-shadow: 1px 1px 0 #000;
}

/* ============ windows ============ */
.window {
  position: absolute;
  left: var(--x, 20vw); top: var(--y, 20vh);
  width: min(var(--w, 440px), calc(100vw - 24px));
  z-index: 100;
  background: var(--win-bg);
  border: 1px solid var(--bone-dim);
  box-shadow: 0 0 0 1px rgba(0,0,0,.9), 7px 7px 0 rgba(0,0,0,.55), 8px 8px 0 rgba(179,18,18,.18);
  display: none;
}
.window.focused {
  border-color: var(--bone);
  box-shadow: 0 0 0 1px rgba(0,0,0,.9), 9px 9px 0 rgba(0,0,0,.6), 10px 10px 0 rgba(179,18,18,.32), 0 0 44px rgba(0,0,0,.55);
}
.window.open { display: block; animation: win-in .16s steps(3); }
@keyframes win-in {
  0% { transform: scale(.86); filter: brightness(2); }
  100% { transform: none; filter: none; }
}
.window.dying { animation: win-out .14s steps(3) forwards; }
@keyframes win-out {
  to { transform: scale(.9); opacity: 0; filter: brightness(3); }
}

.win-bar {
  display: flex; align-items: center;
  background: #16150f;
  color: var(--bone);
  padding: 5px 9px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: .04em;
  user-select: none;
  touch-action: none;
  cursor: grab;
}
/* focused bar: bone with drag-stripes, title on a solid chip (dead-Mac style) */
.window.focused .win-bar {
  background:
    repeating-linear-gradient(0deg, rgba(6,6,6,.3) 0 1px, transparent 1px 3px) 0 4px / 100% calc(100% - 8px) no-repeat,
    var(--bone);
  color: #0a0a0a;
}
.window.focused .win-title,
.window.focused .win-close { background: var(--bone); }
.win-bar:active { cursor: grabbing; }
.win-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; margin-left: -6px; }
.win-close {
  margin-left: auto;
  width: 20px; height: 20px; line-height: 1;
  display: grid; place-items: center;
  border: 1px solid currentColor;
  font-size: 11px;
  flex: none;
}
.win-close:hover { background: var(--red); color: var(--bone); border-color: var(--red); }

.win-body { padding: 16px 18px 18px; }
.win-body p + p { margin-top: .8em; }
.win-body b { color: #fff; font-weight: 500; }

.file-meta {
  font-size: 11px; color: var(--bone-dim);
  margin-bottom: .9em;
}
.redacted {
  color: var(--bone-dim);
  font-style: italic;
}
.redacted::before { content: "▓▓ "; color: var(--red); }

.typewriter { white-space: pre-wrap; min-height: 9em; }
.typewriter::after { content: "▮"; color: var(--red-bright); animation: caret 1s steps(2, start) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* file list (projects folder) */
.filelist { list-style: none; }
.filelist li + li { margin-top: 2px; }
.filelist button {
  display: flex; gap: 8px; align-items: baseline;
  width: 100%; text-align: left;
  padding: 6px 8px;
  font-family: var(--font-mono);
}
.filelist button:hover { background: rgba(179,18,18,.22); color: #fff; }
.filelist i { color: var(--red-bright); font-style: normal; }
.filelist .fsize { margin-left: auto; color: var(--bone-dim); font-size: 11px; }
.filelist + .file-meta { margin: 10px 0 0; }

/* project windows */
.proj-name {
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: 400;
  color: #fff;
  letter-spacing: .05em;
  /* misconverged CRT: red and violet fringes */
  text-shadow: 2px 0 rgba(255,32,32,.45), -2px 0 rgba(139,127,184,.5);
}
.proj-tag { color: var(--red-bright); font-size: 12px; margin: .2em 0 .9em; }
.stack {
  margin-top: .9em;
  font-size: 11px; letter-spacing: .14em;
  color: var(--bone-dim);
}
.proj-link {
  display: inline-block;
  margin-top: 1em;
  padding: 6px 12px;
  border: 1px solid var(--bone-dim);
  font-family: var(--font-ui);
  font-size: 13px;
  text-decoration: none;
}
.proj-link:hover { border-color: var(--red-bright); background: rgba(179,18,18,.2); }

/* photo windows */
.win-photo { padding: 10px; }
.win-photo img { display: block; width: 100%; filter: contrast(1.05); }
.win-photo .file-meta { margin: 8px 2px 0; }

.eye-frame { overflow: hidden; }
.eye-frame img { transition: transform 1.2s ease; will-change: transform; }

/* subtle text corruption on hover */
.glitch-text { position: relative; }
.glitch-text:hover::after {
  content: attr(data-text);
  position: absolute; inset: 0;
  color: var(--red-bright);
  clip-path: inset(30% 0 40% 0);
  transform: translateX(2px);
}

/* contact */
.contactlist { list-style: none; margin: .4em 0 1em; }
.contactlist li + li { margin-top: 8px; }
.contactlist a {
  display: block; padding: 8px 10px;
  border: 1px solid rgba(207,201,186,.25);
  text-decoration: none;
}
.contactlist a:hover { border-color: var(--red-bright); background: rgba(179,18,18,.16); color: #fff; }

/* ============ notes.txt: it writes back ============ */
.win-notes-body { padding: 10px; }
.notes-edit {
  min-height: 220px; max-height: 46vh;
  overflow-y: auto;
  padding: 10px 12px;
  background: #0a0908;
  border: 1px solid var(--bone-dim);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--red-bright);
  outline: none;
  cursor: text;
}
.notes-edit:focus { border-color: var(--bone); }
/* the other writer */
.notes-edit .them {
  font-family: var(--font-whisper);
  font-style: italic;
  font-size: 15px;
  color: var(--ghost);
  text-shadow: 0 0 10px rgba(139, 127, 184, .55);
}
.notes-status {
  display: flex; justify-content: space-between; gap: 10px;
  margin: 8px 2px 0;
}
.notes-status .busy { color: var(--red-bright); }

/* ============ error dialogs (spawned) ============ */
.window.errbox { --w: 340px; border-color: var(--red); box-shadow: 7px 7px 0 rgba(0,0,0,.55), 8px 8px 0 rgba(255,32,32,.4); }
.window.errbox .win-bar,
.window.errbox.focused .win-bar { background: var(--red); color: var(--bone); }
.window.errbox.focused .win-title,
.window.errbox.focused .win-close { background: none; }
.window.errbox .win-close { border-color: var(--bone); }
.errbox .win-body { display: flex; gap: 14px; align-items: flex-start; }
.err-ico { font-size: 30px; color: var(--red-bright); line-height: 1; flex: none; }
.err-msg { font-size: 13px; }
.err-ok {
  margin-top: 12px;
  padding: 5px 26px;
  border: 1px solid var(--bone-dim);
  font-family: var(--font-ui);
}
.err-ok:hover { border-color: var(--red-bright); }

/* ============ carrion.exe ============ */
.icon[data-open="win-bird"] .icon-art { filter: saturate(.2) brightness(1.05); }
.window-game .win-body { padding: 8px; }
#birdCanvas {
  display: block; width: 100%; height: auto;
  image-rendering: pixelated;
  background: #0a0908;
  border: 1px solid var(--bone-dim);
  touch-action: none;
  cursor: pointer;
}
.bird-meta { margin: 6px 2px 0; }

/* what leaks out of the game stays on the desktop */
.gore {
  position: absolute; inset: 0; z-index: 11;
  pointer-events: none;
  opacity: .88;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}

.tray-audio {
  font-size: 13px; line-height: 1;
  padding: 0 4px;
  color: var(--bone-dim);
  filter: grayscale(1) brightness(1.4);
}
.tray-audio.on { color: var(--red-bright); filter: none; }
.tray-audio:hover { filter: none; }

/* ============ the other cursor: violet, late, not always yours ============ */
.ghost-cursor {
  position: fixed; left: 0; top: 0; z-index: 8000;
  width: 18px; height: 18px;
  pointer-events: none;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18"><path d="M2 1 L2 14 L5.6 10.8 L8 16 L10.4 14.9 L8 9.8 L12.6 9.8 Z" fill="%238b7fb8"/></svg>') no-repeat;
  opacity: .42;
  filter: blur(.6px) drop-shadow(0 0 7px rgba(139,127,184,.9));
  mix-blend-mode: screen;
}

/* ============ taskbar ============ */
.taskbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5000;
  display: flex; align-items: stretch; gap: 8px;
  height: 42px;
  padding: 5px 8px;
  background: linear-gradient(#12110c, #070706);
  border-top: 1px solid var(--bone-dim);
  box-shadow: inset 0 1px 0 rgba(207,201,186,.08), 0 -12px 32px rgba(0,0,0,.5);
  font-family: var(--font-ui);
}
.start {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--bone-dim);
  background: rgba(207,201,186,.06);
  font-size: 14px;
  letter-spacing: .04em;
}
.start-logo { height: 17px; width: auto; }
.start:hover .start-logo { filter: drop-shadow(0 0 6px rgba(255,32,32,.8)); }
.start:hover, .start.active { border-color: var(--red-bright); background: rgba(179,18,18,.22); }

.task-buttons { display: flex; gap: 6px; overflow: hidden; }
.task-btn {
  padding: 0 12px;
  border: 1px solid rgba(207,201,186,.22);
  font-size: 12px;
  color: var(--bone-dim);
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-btn.lit { color: var(--bone); border-color: var(--bone-dim); background: rgba(207,201,186,.07); }

.tray {
  margin-left: auto;
  display: flex; align-items: center; gap: 14px;
  font-size: 12px;
  color: var(--bone-dim);
  padding-right: 6px;
}
.tray-clock { color: var(--bone); min-width: 52px; text-align: right; }
.tray-clock.wrong { color: var(--red-bright); }

/* ============ start menu ============ */
.startmenu {
  position: absolute; left: 8px; bottom: 48px; z-index: 5001;
  width: 210px;
  background: var(--win-bg);
  border: 1px solid var(--bone);
  box-shadow: 6px 6px 0 rgba(0,0,0,.5);
  padding: 6px;
  font-family: var(--font-ui);
}
.startmenu button {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; font-size: 13px;
}
.startmenu button:hover { background: rgba(179,18,18,.25); color: #fff; }
.startmenu hr { border: 0; border-top: 1px solid rgba(207,201,186,.2); margin: 6px 4px; }

/* ============ shutdown ============ */
.shutdown {
  position: fixed; inset: 0; z-index: 10001;
  background: #000;
  display: grid; place-items: center;
}
.shutdown p {
  font-family: var(--font-ui);
  font-size: clamp(15px, 2.6vw, 24px);
  color: var(--bone);
  text-align: center;
  padding: 0 20px;
}
.shutdown p.turn { color: var(--red-bright); }

/* ============ mobile ============ */
@media (max-width: 640px) {
  /* icons: clean 3-column grid */
  .icons {
    flex-direction: row; flex-wrap: wrap;
    top: 16px; left: 12px; right: 12px;
    gap: 10px 0;
    justify-content: space-between;
  }
  .icon { width: 31%; padding: 10px 4px; }
  .icon-art { width: 54px; height: 54px; font-size: 27px; }

  /* windows: full sheets with dimmed desktop behind */
  .window {
    left: 10px !important; right: 10px; top: 16px !important;
    width: auto !important;
    max-height: calc(100dvh - 84px);
    overflow-y: auto;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .6), 7px 7px 0 rgba(0,0,0,.55);
  }
  .win-body { padding: 15px 15px 17px; }

  /* error dialogs stay small, centered */
  .window.errbox {
    top: 26vh !important;
    left: 26px !important; right: 26px;
    max-height: none;
  }

  /* bigger taskbar */
  .taskbar { height: 52px; padding: 7px 10px; }
  .start { font-size: 15px; }
  .start-logo { height: 20px; }
  .task-btn { padding: 0 10px; max-width: 110px; }
  .tray-item { display: none; }
  .tray-clock { font-size: 14px; }

  /* sigil: smaller, tucked low so it doesn't fight the icons */
  .wall-sigil { width: 44vw; top: auto; bottom: 12vh; transform: none; }

  /* no cursor to haunt on phones */
  .ghost-cursor { display: none; }

  /* carrion.exe: canvas fits the sheet */
  #birdCanvas { max-height: calc(100dvh - 190px); object-fit: contain; }
}

/* ============ reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  .boot-text, .grain, .typewriter::after, .whisper { animation: none; }
  .window.open, .window.dying { animation: none; }
  .icon:hover .icon-art { animation: none; }
  .ghost-cursor { display: none; }
  .wall-static { display: none; }
  .wall {
    background: #000 url("../assets/wallpaper.png") center / cover no-repeat;
  }
}
