/* v7 - The Desk. Gruvbox Material, a small warm OS. */

:root[data-theme="dark"] {
  color-scheme: dark;
  --desk: #282828;
  --win: #32302f;
  --panel: #3c3836;
  --border: #504945;
  --fg: #d4be98;
  --muted: #a89984;
  --orange: #e78a4e;
  --yellow: #d8a657;
  --green: #a9b665;
  --aqua: #89b482;
  --blue: #7daea3;
  --red: #ea6962;
  --purple: #d3869b;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.42), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-idle: 0 6px 18px rgba(0, 0, 0, 0.3);
  --wp-grain: url("assets/wp-dark-grain.webp");
  --wp-weave: url("assets/wp-dark-weave.webp");
  --wp-opacity: 0.5;
}

:root[data-theme="light"] {
  color-scheme: light;
  --desk: #fbf1c7;
  --win: #f9f5d7;
  --panel: #f2e5bc;
  --border: #ddccab;
  --fg: #654735;
  --muted: #7c6f64;
  --orange: #c35e0a;
  --yellow: #b47109;
  --green: #6c782e;
  --aqua: #4c7a5d;
  --blue: #45707a;
  --red: #c14a4a;
  --purple: #945e80;
  --shadow: 0 12px 28px rgba(101, 71, 53, 0.26), 0 2px 6px rgba(101, 71, 53, 0.15);
  --shadow-idle: 0 5px 14px rgba(101, 71, 53, 0.16);
  --wp-grain: url("assets/wp-light-grain.webp");
  --wp-weave: url("assets/wp-light-weave.webp");
  --wp-opacity: 0.6;
}

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

html, body { height: 100%; }

body {
  font-family: "iA Writer Quattro", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--desk);
  color: var(--fg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

::selection { background: var(--yellow); color: var(--desk); }

a { color: var(--aqua); text-decoration-color: color-mix(in srgb, var(--aqua) 45%, transparent); text-underline-offset: 3px; }
a:hover { color: var(--orange); text-decoration-color: var(--orange); }

:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
  border-radius: 2px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- menu bar ---------- */

.menubar {
  position: relative;
  z-index: 500;
  flex: none;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-family: "iA Writer Mono", monospace;
  font-size: 12px;
}

.mb-left { position: relative; display: flex; align-items: center; gap: 12px; height: 100%; }
.mb-right { display: flex; align-items: center; gap: 14px; }

.pd-btn {
  font-family: "iA Writer Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--orange);
  padding: 3px 8px;
  border-radius: 3px;
}
.pd-btn:hover, .pd-btn[aria-expanded="true"] { background: var(--border); }

.mb-app { color: var(--muted); }

.pd-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  list-style: none;
  background: var(--win);
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 600;
}
.pd-menu button {
  display: block;
  width: 100%;
  text-align: left;
  font-family: "iA Writer Mono", monospace;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 3px;
  color: var(--fg);
}
.pd-menu button:hover { background: var(--panel); color: var(--orange); }
.pd-sep { border-top: 1px solid var(--border); margin: 5px 4px; }

.mb-bakeoff {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
}
.mb-bakeoff:hover { color: var(--orange); }

.mb-theme {
  font-family: "iA Writer Mono", monospace;
  font-size: 11px;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 8px;
}
.mb-theme::before { content: "◐ "; color: var(--yellow); }
.mb-theme:hover { background: var(--border); }

.mb-clock { color: var(--fg); font-variant-numeric: tabular-nums; }

/* ---------- desktop ---------- */

.desk {
  position: relative;
  flex: 1;
  overflow: hidden;
}
.desk::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--wp-grain);
  background-size: cover;
  background-position: center;
  opacity: var(--wp-opacity);
  pointer-events: none;
}
:root[data-wallpaper="weave"] .desk::before { background-image: var(--wp-weave); }
:root[data-wallpaper="flat"] .desk::before { display: none; }

/* ---------- windows ---------- */

.window {
  position: absolute;
  background: var(--win);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-idle);
  overflow: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
.window.active { box-shadow: var(--shadow); }
.window.hidden-win { display: none; }
.window.minimizing, .window.opening-from {
  opacity: 0;
  transform: translateY(48px) scale(0.72);
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: 0 6px 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.titlebar:active { cursor: grabbing; }
.titlebar .title {
  font-family: "iA Writer Mono", monospace;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.window.active .titlebar .title { color: var(--fg); }

.win-btns { display: flex; gap: 4px; }
.wb {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.wb svg { width: 9px; height: 9px; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.wb-min:hover { background: var(--border); color: var(--yellow); }
.wb-close:hover { background: var(--border); color: var(--red); }

.body { padding: 18px 20px 20px; }

/* about + building prose */
.body-prose { max-width: 46ch; }
.body-prose h1 {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--orange);
}
.body-prose .filehead {
  font-family: "iA Writer Mono", monospace;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--yellow);
  margin-bottom: 12px;
}
.body-prose p { margin-bottom: 12px; }
.body-prose p:last-child { margin-bottom: 0; }
.body-prose .quiet { color: var(--muted); font-size: 14px; }

/* links window */
.body-files { padding: 10px; }
.filerow {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 9px 12px;
  border-radius: 4px;
  font-family: "iA Writer Mono", monospace;
  font-size: 13px;
  text-decoration: none;
  color: var(--fg);
}
.filerow:hover { background: var(--panel); color: var(--fg); }
.fr-name { color: var(--blue); min-width: 11ch; }
.filerow:hover .fr-name { color: var(--orange); }
.fr-handle { color: var(--muted); flex: 1; }
.fr-arrow { color: var(--muted); }
.filerow:hover .fr-arrow { color: var(--orange); }

/* radio.log */
.body-log {
  height: 360px;
  overflow-y: auto;
  font-family: "iA Writer Mono", monospace;
  font-size: 12.5px;
  line-height: 1.8;
  padding: 14px 18px;
  scrollbar-width: thin;
}
.loglist { list-style: none; }
.loglist li { white-space: normal; padding-left: 6ch; text-indent: -6ch; }
.loglist li.unlit { display: none; }
.lt { color: var(--green); margin-right: 1ch; }
.logsep { color: var(--border); }
.lognote { color: var(--yellow); }
.logcursor {
  display: inline-block;
  width: 7px;
  height: 13px;
  background: var(--orange);
  vertical-align: -2px;
}
@media (prefers-reduced-motion: no-preference) {
  .logcursor { animation: blink 1.1s steps(1) infinite; }
  @keyframes blink { 50% { opacity: 0; } }
}

/* settings */
.body-settings { font-family: "iA Writer Mono", monospace; font-size: 12px; }
.setgroup { border: none; margin-bottom: 16px; }
.setgroup legend {
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 10.5px;
  margin-bottom: 7px;
}
.seg { display: flex; gap: 6px; }
.segbtn {
  font-family: "iA Writer Mono", monospace;
  font-size: 12px;
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}
.segbtn:hover { color: var(--fg); background: var(--panel); }
.segbtn[aria-pressed="true"] {
  color: var(--desk);
  background: var(--orange);
  border-color: var(--orange);
}
.set-hint { color: var(--muted); font-size: 11px; line-height: 1.6; margin-top: 2px; }

/* ---------- dock ---------- */

.dock {
  position: relative;
  z-index: 500;
  flex: none;
  display: flex;
  justify-content: center;
  padding: 10px 12px 12px;
}
.dock-inner {
  display: flex;
  align-items: stretch;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px 5px;
  box-shadow: var(--shadow-idle);
}
.dock-apps, .dock-links { display: flex; gap: 6px; }
.dock-sep { width: 1px; background: var(--border); margin: 2px 6px; }

.dock-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 62px;
  padding: 5px 2px 3px;
  border-radius: 6px;
  text-decoration: none;
}
.dock-item:hover { background: var(--border); }
.di-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.di-icon .fill { fill: var(--fg); stroke: none; }
.di-label {
  font-family: "iA Writer Mono", monospace;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.dock-item:hover .di-label { color: var(--fg); }

.di-ig .di-icon { stroke: var(--purple); }
.di-tt .di-icon { stroke: var(--aqua); }
.di-tt .di-icon .fill { fill: var(--aqua); }
.di-x .di-icon { stroke: var(--blue); }
.di-gh .di-icon { stroke: var(--orange); }

/* open/minimized indicator dot */
.dock-item::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
}
.dock-item.open::after { background: var(--muted); }
.dock-item.mini::after { background: var(--yellow); }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .window { transition: none; }
  .window.minimizing, .window.opening-from { opacity: 1; transform: none; }
}

/* ---------- mobile: stack of cards ---------- */

@media (max-width: 760px) {
  html, body { height: auto; }
  body { overflow: visible; display: block; }

  .menubar {
    position: sticky;
    top: 0;
    height: 34px;
  }
  .mb-app { display: none; }

  .desk {
    overflow: visible;
    padding: 18px 14px 24px;
    min-height: calc(100vh - 34px - 76px);
  }
  .window {
    position: static !important;
    width: auto !important;
    max-width: 480px;
    margin: 0 auto 16px;
    box-shadow: var(--shadow-idle);
  }
  .window.hidden-win { display: block; }
  .win-btns { display: none; }
  .titlebar { cursor: default; touch-action: auto; }
  .titlebar .title { color: var(--fg); }

  .body { padding: 16px 18px 18px; }
  .body-log { height: auto; }
  .loglist li.unlit { display: list-item; }
  .logcursor { display: none; }

  .pd-menu [data-menu="tidy"] { display: none; }

  /* settings: hide desktop-only bits */
  #win-settings .setgroup:nth-of-type(3), #win-settings .set-hint { display: none; }

  .dock {
    position: static;
    padding: 2px 14px calc(16px + env(safe-area-inset-bottom));
    background: none;
  }
  .dock-inner {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-idle);
    padding: 8px 6px;
    width: 100%;
    max-width: 400px;
    justify-content: center;
  }
  .dock-apps, .dock-sep { display: none; }
  .dock-links { width: 100%; justify-content: space-around; }
  .dock-item::after { display: none; }
  .dock-item { width: 70px; }
}
