/* ---------- Desktop / layout ---------- */
/* Scoped: XP.css sizes its own chrome (e.g. .title-bar height) assuming content-box. */
.desktop, .taskbar, .start-menu, .modal, .q-card, .map-wrap, .map-tip,
.sunken-panel, .answer-buttons button { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  /* A loose nod to a certain green hill under a blue sky. */
  background:
    radial-gradient(ellipse 140% 55% at 25% 108%, #6fb440 0 48%, transparent 49%),
    radial-gradient(ellipse 120% 50% at 90% 112%, #4f9a2c 0 46%, transparent 47%),
    linear-gradient(#2f6fd6 0%, #5c9ae8 45%, #b6d8f7 75%, #d9ecfb 100%);
  background-attachment: fixed;
  padding-bottom: calc(38px + env(safe-area-inset-bottom));
}

.desktop {
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-template-columns: 75px minmax(330px, 400px) minmax(0, 1fr) minmax(280px, 340px);
  grid-template-areas: "icons left brain right";
  align-items: start;
}
/* Wide: the side windows stack in their own columns, so their heights don't
   leave gaps. Narrower: the columns dissolve and windows use the grid areas. */
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.col-left { grid-area: left; }
.col-right { grid-area: right; }
.win-game  { grid-area: game; }
.win-brain { grid-area: brain; }
.win-cands { grid-area: cands; }
.win-ahead { grid-area: ahead; }
.win-log   { grid-area: log; }
.desk-icons { grid-area: icons; }

@media (max-width: 1150px) {
  /* Two columns: 20Q + Log on the left, Brain with Candidates + Predictions
     under it on the right. The last row absorbs any extra height so nothing
     opens a gap between stacked windows. */
  .desktop {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "left  brain"
      "left  right"
      "icons icons";
    grid-template-rows: auto 1fr auto;
  }
}
@media (max-width: 760px) {
  .col { display: contents; }
  .desktop {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "game" "brain" "cands" "ahead" "log" "icons";
    padding: 8px;
    gap: 10px;
  }
}

.window { min-width: 0; }
.window.closed { display: none; }
.window.minimized > .window-body,
.window.minimized > .status-bar { display: none; }
.window.maximized {
  position: fixed;
  inset: 0 0 calc(30px + env(safe-area-inset-bottom)) 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.window.maximized > .window-body { flex: 1; overflow: auto; min-height: 0; }
.title-bar-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hint-text { color: #555; margin: 6px 0 0; }

/* ---------- Game window ---------- */
.q-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.q-header span { white-space: nowrap; font-weight: bold; }
.q-header .progress-indicator { flex: 1; }

.q-card {
  background: #fff;
  border: 1px solid #7f9db9;
  border-radius: 3px;
  padding: 14px 14px 16px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  box-shadow: inset 1px 1px 0 #e5ecf7;
}
.q-kicker { color: #666; font-size: 11px; margin-bottom: 6px; }
.q-text {
  font-family: "Trebuchet MS", Tahoma, sans-serif;
  font-weight: bold;
  font-size: 22px;
  line-height: 1.2;
  color: #0b2a6f;
  overflow-wrap: anywhere;
}
.q-card.guess { background: #fffbe6; border-color: #e0b84b; }
.q-card.won { background: #ebffe6; border-color: #63b04d; }
.q-card.stumped { background: #ffeeee; border-color: #d06262; }

.answer-form { margin-top: 10px; }
.answer-form .field-row { display: flex; gap: 6px; }
.answer-form input[type=text] { flex: 1; min-width: 0; height: 26px; font-size: 13px; }
.answer-hint { min-height: 1.4em; margin-top: 3px; color: #555; }
.answer-hint.ok { color: #0a6b0a; }
.answer-hint.bad { color: #a00; }

.answer-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
  margin-top: 4px;
}
.answer-buttons button { grid-column: span 2; min-width: 0; padding: 0 2px; min-height: 28px; font-size: 12px; }
.answer-buttons button.big { grid-column: span 3; min-height: 38px; font-size: 15px; font-weight: bold; }
.answer-buttons button.wide { grid-column: span 6; min-height: 34px; font-size: 14px; font-weight: bold; }

/* ---------- Brain window ---------- */
.brain-toolbar { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.brain-toolbar .field-row { display: flex; align-items: center; gap: 6px; margin: 0; }
.brain-toolbar input[type=text] { flex: 1; min-width: 0; }
.map-wrap {
  position: relative;
  background: #fff;
  border: 1px solid #7f9db9;
  touch-action: manipulation;
}
.map-wrap canvas { display: block; width: 100%; }
.map-tip {
  position: absolute;
  pointer-events: none;
  background: #ffffe1;
  border: 1px solid #000;
  padding: 3px 6px;
  font-size: 11px;
  white-space: nowrap;
  box-shadow: 2px 2px 3px rgba(0,0,0,.3);
  z-index: 2;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.track-info { margin: 6px 0 0; padding: 5px 7px; background: #eaf7e6; border: 1px solid #8fc27f; }
.win-brain.maximized .window-body { display: flex; flex-direction: column; }
.win-brain.maximized .map-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.win-brain.maximized .map-wrap canvas { width: auto; }

/* ---------- Tables ---------- */
.sunken-panel {
  overflow: auto;
  background: #fff;
  border: 1px solid #7f9db9;
}
.sunken-panel table { width: 100%; border-collapse: collapse; }
.sunken-panel th {
  position: sticky; top: 0;
  background: linear-gradient(#fff, #ebeadb);
  border-bottom: 1px solid #c7c5b2;
  border-right: 1px solid #e2e1d1;
  text-align: left; font-weight: normal; padding: 3px 5px;
}
.sunken-panel td { padding: 3px 5px; vertical-align: middle; }
table.interactive tbody tr { cursor: pointer; }
table.interactive tbody tr:hover { background: #e8f0fc; }
table.interactive tbody tr.highlighted,
table.interactive tbody tr.highlighted:hover { background: #316ac5; color: #fff; }

.cands-panel { max-height: 330px; }
.cands-table td.num, #cands-table td:first-child { color: #777; width: 2em; text-align: right; }
#cands-table tr.highlighted td:first-child { color: #dfe8ff; }
#cands-table td.name { overflow-wrap: anywhere; }
#cands-table td.score { width: 38%; }
.scorebar { display: flex; align-items: center; gap: 5px; }
.scorebar b { font-weight: normal; width: 2.6em; text-align: right; font-variant-numeric: tabular-nums; }
.scorebar i { display: block; height: 8px; background: linear-gradient(#ffb347, #f07b00); border: 1px solid #c25e00; min-width: 1px; }
.delta { width: 2.8em; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: #0a7a0a; }
.delta.down { color: #b00; }
tr.highlighted .delta { color: #fff; }
.confidence { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.confidence .progress-indicator { flex: 1; }
.confidence span:last-child { width: 3em; text-align: right; }

.log-controls { display: flex; flex-wrap: wrap; gap: 4px; }
.log-controls button { min-width: 0; padding: 0 8px; }
.scrub-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.scrub-row input { flex: 1; }
.scrub-row span { width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }
.log-panel { max-height: 360px; }
.win-log.maximized .log-panel, .win-cands.maximized .cands-panel { max-height: none; }
#log-table td.n { color: #777; width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }
#log-table td.ans { white-space: nowrap; text-align: right; }
#log-table td.mark { width: 1.4em; text-align: center; }
#log-table tr.future { opacity: .45; font-style: italic; }
#log-table tr.highlighted td.n { color: #dfe8ff; }
.badge { display: inline-block; padding: 0 5px; border-radius: 2px; border: 1px solid rgba(0,0,0,.25); color: #000; background: #eee; }
.badge.yes { background: #c9f0c0; }
.badge.no { background: #f6c8c8; }
.badge.guess { background: #ffe9a8; }
.mark.agree { color: #0a7a0a; }
.mark.disagree { color: #c00; font-weight: bold; }

/* ---------- Lookahead ---------- */
fieldset + fieldset { margin-top: 10px; }
.branch { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 8px; padding: 5px 0; border-bottom: 1px dotted #c7c5b2; }
.branch:last-child { border-bottom: 0; }
.branch .who { font-weight: bold; white-space: nowrap; }
.branch .what { overflow-wrap: anywhere; }
.branch .next { grid-column: 2; color: #555; overflow-wrap: anywhere; }
.qrow { padding: 4px 3px; border-radius: 2px; cursor: default; }
.qrow:hover, .qrow.painting { background: #e8f0fc; }
.qrow.chosen .qtext::before { content: "▶ "; color: #316ac5; }
.qrow .qtext { overflow-wrap: anywhere; }
.qrow.chosen .qtext { font-weight: bold; }
.split { display: flex; height: 7px; margin-top: 3px; border: 1px solid #888; background: #eee; }
.split .y { background: #4caf50; }
.split .n { background: #e05050; }

/* ---------- Taskbar ---------- */
.taskbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(30px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: stretch;
  background: linear-gradient(#3168d5 0%, #4993e6 4%, #2a6bd9 12%, #245ddb 50%, #2157d6 88%, #1941a5 100%);
  z-index: 100;
  font-family: Tahoma, "Segoe UI", sans-serif;
}
.taskbar button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  color: #fff;
  font-size: 12px;
  font-family: Tahoma, "Segoe UI", sans-serif;
}
.taskbar .start-button {
  height: 30px;
  padding: 0 22px 0 12px;
  border-radius: 0 10px 10px 0;
  background: linear-gradient(#3c9b3c 0%, #67c35f 10%, #3fa53b 30%, #31932e 80%, #257d23 100%);
  box-shadow: inset -1px -1px 2px rgba(0,0,0,.35), inset 1px 1px 2px rgba(255,255,255,.4);
  font-style: italic; font-weight: bold; font-size: 17px;
  text-shadow: 1px 1px 2px rgba(0,0,0,.5);
  display: flex; align-items: center;
}
.taskbar .start-button:hover { filter: brightness(1.08); }
.task-buttons { flex: 1; display: flex; gap: 3px; padding: 3px 6px; overflow-x: auto; scrollbar-width: none; }
.task-buttons button {
  flex: 0 1 150px; min-width: 64px;
  padding: 0 8px;
  border-radius: 3px;
  background: linear-gradient(#5a9bf7, #3c81f3);
  border: 1px solid #1c4fb8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 22px;
}
.task-buttons button.active { background: linear-gradient(#1e52b7, #1a47a6); box-shadow: inset 1px 1px 2px rgba(0,0,0,.5); }
.task-buttons button.off { opacity: .7; }
.tray {
  display: flex; align-items: center;
  padding: 0 12px;
  color: #fff; font-size: 12px;
  background: linear-gradient(#0f9de8, #1290e0 50%, #0d7cd0);
  border-left: 1px solid #0b5fa8;
  box-shadow: inset 1px 0 1px rgba(255,255,255,.3);
}
@media (max-width: 480px) {
  .tray { display: none; }
  .task-buttons button { flex-basis: 90px; }
}

.start-menu {
  position: fixed; left: 0; bottom: calc(30px + env(safe-area-inset-bottom));
  z-index: 101;
  width: 220px;
  background: #fff;
  border: 2px solid #1f4fb6;
  border-radius: 6px 6px 0 0;
  box-shadow: 3px -3px 8px rgba(0,0,0,.35);
  overflow: hidden;
}
.start-menu-head {
  padding: 10px; color: #fff; font-weight: bold; font-size: 14px;
  font-family: "Trebuchet MS", Tahoma, sans-serif;
  background: linear-gradient(#1f5ed8, #3d86e8);
}
.start-menu button {
  all: unset; box-sizing: border-box; display: block; width: 100%;
  padding: 8px 12px; cursor: pointer; font-size: 12px;
}
.start-menu button:hover { background: #316ac5; color: #fff; }

.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.25);
  padding: 12px;
}
.modal[hidden] { display: none; }
.about-window { max-width: 460px; }
.about-window ul { padding-left: 18px; }
.about-window li { margin-bottom: 4px; }

/* Touch-friendly sizing */
@media (pointer: coarse) {
  .answer-form input[type=text], .brain-toolbar input[type=text] { font-size: 16px; height: 32px; }
  .answer-buttons button { min-height: 40px; font-size: 13px; }
  .answer-buttons button.big { min-height: 48px; }
  .log-controls button, .brain-toolbar button { min-height: 32px; }
  .sunken-panel td { padding: 6px 5px; }
}

/* ---------- Desktop icons (after ~/Projects/away-message) ---------- */
.desk-icons {
  --select: #316ac5;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 2px;
  user-select: none;
  -webkit-user-select: none;
}
.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 75px;
  padding-top: 2px;
  color: #fff;
  text-decoration: none;
  font-family: Tahoma, Verdana, "Segoe UI", sans-serif;
  font-size: 11px;
  -webkit-tap-highlight-color: transparent;
  outline: none !important;
}
.icon-image {
  position: relative;
  width: 32px;
  height: 32px;
  margin-bottom: 4px;
  background: var(--icon) center / 32px 32px no-repeat;
}
/* Selected icons are tinted with the selection color, as in Windows */
.icon-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--select);
  opacity: 0;
  -webkit-mask: var(--icon) center / 32px 32px no-repeat;
  mask: var(--icon) center / 32px 32px no-repeat;
}
.desktop-icon:focus .icon-image::after { opacity: 0.5; }
.icon-label {
  box-sizing: border-box;
  max-width: 75px;
  padding: 1px 2px;
  line-height: 13px;
  text-align: center;
  text-shadow: 1px 1px 1px #000;
}
.desktop-icon:focus .icon-label { background: var(--select); text-shadow: none; }
.desktop-icon:focus-visible .icon-label { outline: 1px dotted #fff; }
[data-icon="home"] { --icon: url(icons/home-xp.png); }
[data-icon="profile"] { --icon: url(icons/profile-xp.png); }

@media (max-width: 1150px) {
  /* No room for a column, so the icons sit in a row below the windows */
  .desk-icons { flex-direction: row; justify-content: center; gap: 8px; padding: 4px 0; }
}
