/* ==========================================================================
   desktop.css
   Shared layer for radicaldove: color modes, global reset, window chrome.
   Every page links this first, then its own stylesheet.
   Sizes are in rem so the reader's browser font setting is respected.
   ========================================================================== */

/* --- Color modes --- */
:root,
[data-theme="default"] {
  --text-scale: 1;
  --body-bg: #008080;
  --window-face: #c0c0c0;
  --window-content-bg: #ffffff;
  --bevel-light: #ffffff;
  --bevel-light-soft: #dfdfdf;
  --bevel-dark-soft: #808080;
  --bevel-dark: #404040;
  --text-color: #000000;
  --text-secondary: #404040;
  --text-muted: #606060;
  --titlebar-bg: linear-gradient(90deg, #000080 0%, #1084d0 100%);
  --titlebar-fg: #ffffff;
  --titlebar-inactive: linear-gradient(90deg, #808080 0%, #b5b5b5 100%);
  --link-color: #0000a8;
  --link-visited: #6a006a;
  --highlight-bg: #000080;
  --highlight-fg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.4);
  --focus-outline: 2px solid #000000;
}

[data-theme="dark"] {
  --body-bg: #0d2530;
  --window-face: #3a3a3a;
  --window-content-bg: #2a2a2a;
  --bevel-light: #6e6e6e;
  --bevel-light-soft: #4a4a4a;
  --bevel-dark-soft: #1c1c1c;
  --bevel-dark: #0a0a0a;
  --text-color: #e8e8e8;
  --text-secondary: #c8c8c8;
  --text-muted: #a8a8a8;
  --titlebar-bg: linear-gradient(90deg, #000080 0%, #1084d0 100%);
  --titlebar-fg: #ffffff;
  --titlebar-inactive: linear-gradient(90deg, #404040 0%, #606060 100%);
  --link-color: #6cb6ff;
  --link-visited: #c898ff;
  --highlight-bg: #6cb6ff;
  --highlight-fg: #000000;
  --shadow: rgba(0, 0, 0, 0.7);
  --focus-outline: 2px solid #ffffff;
}

[data-theme="contrast"] {
  --body-bg: #000000;
  --window-face: #ffffff;
  --window-content-bg: #ffffff;
  --bevel-light: #ffffff;
  --bevel-light-soft: #ffffff;
  --bevel-dark-soft: #000000;
  --bevel-dark: #000000;
  --text-color: #000000;
  --text-secondary: #000000;
  --text-muted: #000000;
  --titlebar-bg: #000000;
  --titlebar-fg: #ffffff;
  --titlebar-inactive: #000000;
  --link-color: #0000ee;
  --link-visited: #551a8b;
  --highlight-bg: #000000;
  --highlight-fg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.5);
  --focus-outline: 3px solid #000000;
}

/* --- Global reset --- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  background-color: var(--body-bg);
  color: var(--text-color);
  font-family: "Tahoma", "Segoe UI", "MS Sans Serif", Geneva, sans-serif;
  font-size: 0.8125rem;
  min-height: 100vh;
}

[data-theme="contrast"] body { background-image: none; }

a { color: var(--link-color); text-decoration: underline; }
a:visited { color: var(--link-visited); }

:focus-visible { outline: var(--focus-outline); outline-offset: 2px; }

/* --- Accessibility helpers --- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--titlebar-bg);
  color: var(--titlebar-fg);
  padding: 8px 16px;
  text-decoration: none;
  font-weight: bold;
  z-index: 5000;
}
.skip-link:focus { left: 8px; top: 8px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Window shell --- */
.app-body { overflow-y: auto; }

.app-window {
  width: 100%;
  max-width: 980px;
  margin: 16px auto;
  background-color: var(--window-face);
  border: 2px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  box-shadow: 1px 1px 0 var(--bevel-dark), 4px 4px 8px var(--shadow);
  display: flex;
  flex-direction: column;
}

.app-titlebar {
  background: var(--titlebar-bg);
  color: var(--titlebar-fg);
  padding: 3px 3px 3px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 0.8125rem;
  margin: 2px;
  user-select: none;
}

.app-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 10px;
}

.app-title-icon {
  display: inline-block;
  width: 16px;
  height: 14px;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--window-face);
  border: 1px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  position: relative;
}
.app-title-icon::after {
  content: "\25A6";
  position: absolute;
  inset: 0;
  color: var(--text-color);
  font-size: 0.6875rem;
  line-height: 12px;
  text-align: center;
}

.window-controls,
.titlebar-buttons { display: flex; gap: 2px; flex-shrink: 0; }

.window-btn {
  width: 20px;
  height: 18px;
  min-width: 20px;
  padding: 0;
  font-family: inherit;
  font-size: 0.625rem;
  font-weight: bold;
  line-height: 1;
  color: var(--text-color);
  background: var(--window-face);
  border: 1px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.window-btn:active {
  border-top-color: var(--bevel-dark-soft);
  border-left-color: var(--bevel-dark-soft);
  border-right-color: var(--bevel-light);
  border-bottom-color: var(--bevel-light);
}
.window-btn:focus-visible { outline: var(--focus-outline); outline-offset: -3px; }

.close-link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-color);
}
.close-link:visited { color: var(--text-color); }

/* --- Menubar and dropdowns --- */
.menubar {
  background: var(--window-face);
  border-bottom: 1px solid var(--bevel-dark-soft);
  padding: 2px 4px;
  margin: 0 2px;
  display: flex;
  gap: 4px;
  align-items: center;
  font-size: 0.75rem;
}

.menu-item {
  padding: 4px 8px;
  cursor: default;
  user-select: none;
  color: var(--text-color);
  background: none;
  border: 0;
  box-shadow: none;
  font: inherit;
  min-height: 0;
}
.menu-item u { text-decoration: underline; }
a.menu-item { text-decoration: none; color: inherit; display: block; }
.menu-item:hover,
.menu-item:focus { background: var(--highlight-bg); color: var(--highlight-fg); }
.menu-item.has-dropdown { position: relative; }

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--window-face);
  border: 2px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  box-shadow: 2px 2px 5px var(--shadow);
  z-index: 9999;
  flex-direction: column;
  min-width: 190px;
  padding: 2px;
}
.menu-item.has-dropdown.open .dropdown-menu { display: flex; }
.menu-item.has-dropdown.open { background: var(--highlight-bg); color: var(--highlight-fg); }

.dropdown-item {
  text-align: left;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 6px 16px;
  width: 100%;
  min-height: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text-color);
}
a.dropdown-item { display: block; text-decoration: none; }
.dropdown-item:hover,
.dropdown-item:focus { background: var(--highlight-bg); color: var(--highlight-fg); outline: none; }
.dropdown-separator {
  height: 1px;
  background: var(--bevel-dark-soft);
  border-bottom: 1px solid var(--bevel-light);
  margin: 3px 2px;
}

/* --- Toolbar --- */
.toolbar {
  background: var(--window-face);
  margin: 2px 2px 0 2px;
  padding: 14px 8px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: stretch;
  border-bottom: 1px solid var(--bevel-light);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid;
  border-top-color: var(--bevel-dark-soft);
  border-left-color: var(--bevel-dark-soft);
  border-right-color: var(--bevel-light);
  border-bottom-color: var(--bevel-light);
  position: relative;
}
.toolbar-group button { padding: 4px 10px; }

.group-label {
  position: absolute;
  top: -8px;
  left: 6px;
  background: var(--window-face);
  padding: 0 4px;
  font-size: 0.6875rem;
  font-weight: normal;
  color: var(--text-secondary);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

/* --- Buttons --- */
.btn,
button {
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text-color);
  background: var(--window-face);
  border: 2px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  box-shadow: inset 1px 1px 0 var(--bevel-light-soft), inset -1px -1px 0 var(--bevel-dark);
  padding: 4px 12px;
  min-height: 24px;
  min-width: 32px;
  cursor: pointer;
  line-height: 1.2;
}

button:hover { filter: brightness(1.03); }

button:active,
button[aria-pressed="true"] {
  border-top-color: var(--bevel-dark-soft);
  border-left-color: var(--bevel-dark-soft);
  border-right-color: var(--bevel-light);
  border-bottom-color: var(--bevel-light);
  box-shadow: inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light-soft);
}

button:focus-visible { outline: var(--focus-outline); outline-offset: -4px; }

button[disabled] { color: var(--text-muted); cursor: not-allowed; filter: none; }

/* Links styled as buttons */
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-color);
}
a.btn:visited { color: var(--text-color); }

/* Touch targets */
@media (pointer: coarse) {
  button, .btn { min-height: 36px; min-width: 36px; padding: 6px 14px; }
  .window-btn { min-width: 30px; height: 26px; }
  .dropdown-item { padding: 10px 16px; }
  .menu-item { padding: 8px 10px; }
}

/* --- Status bar --- */
.statusbar {
  margin: 2px;
  background: var(--window-face);
  padding: 4px 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 0.6875rem;
  border-top: 1px solid var(--bevel-light);
}

.status-section {
  border: 1px solid;
  border-top-color: var(--bevel-dark-soft);
  border-left-color: var(--bevel-dark-soft);
  border-right-color: var(--bevel-light);
  border-bottom-color: var(--bevel-light);
  padding: 2px 8px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
}

.retro-progress {
  display: inline-block;
  width: 150px;
  height: 14px;
  background: var(--window-content-bg);
  margin-left: 8px;
  border: 1px solid var(--bevel-dark-soft);
  overflow: hidden;
}
.retro-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--highlight-bg);
  transition: width 0.1s;
}

/* --- Dialogs --- */
.dialog {
  display: none;
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: var(--window-face);
  border: 2px solid;
  border-top-color: var(--bevel-light);
  border-left-color: var(--bevel-light);
  border-right-color: var(--bevel-dark-soft);
  border-bottom-color: var(--bevel-dark-soft);
  box-shadow: 4px 4px 0 var(--bevel-dark), 6px 6px 16px var(--shadow);
  z-index: 1000;
  font-size: 0.75rem;
  color: var(--text-color);
  flex-direction: column;
}
.dialog.open { display: flex; }
.dialog.dragging { user-select: none; }

.dialog-titlebar {
  background: var(--titlebar-bg);
  color: var(--titlebar-fg);
  padding: 3px 3px 3px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 0.8125rem;
  margin: 2px 2px 0 2px;
  cursor: move;
  flex-shrink: 0;
  user-select: none;
}

.dialog-content {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}

.dialog-footer,
.dialog-buttonbar {
  padding: 8px 12px 10px 12px;
  margin: 0 2px 2px 2px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.dialog-footer::before,
.dialog-buttonbar::before {
  content: "";
  display: block;
  border-top: 1px solid var(--bevel-dark-soft);
  border-bottom: 1px solid var(--bevel-light);
  margin: -8px -12px 8px -12px;
}
.dialog-footer button,
.dialog-buttonbar button { min-width: 80px; }
.btn-primary { font-weight: bold; min-width: 80px; }

/* --- Group box --- */
.groupbox {
  margin: 0 0 14px 0;
  padding: 12px 14px 10px 14px;
  border: 1px solid;
  border-top-color: var(--bevel-dark-soft);
  border-left-color: var(--bevel-dark-soft);
  border-right-color: var(--bevel-light);
  border-bottom-color: var(--bevel-light);
  position: relative;
}
.groupbox-legend {
  position: absolute;
  top: -8px;
  left: 10px;
  background: var(--window-face);
  padding: 0 6px;
  font-weight: bold;
  font-size: 0.75rem;
  color: var(--text-color);
}

/* --- Small screens --- */
@media (max-width: 720px) {
  .app-window { margin: 0; max-width: 100%; border-width: 0; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 20px; }
  .toolbar-group { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .toolbar-actions { margin-left: 0; justify-content: flex-end; }
  .statusbar { flex-direction: column; align-items: stretch; }
  .dialog { width: calc(100vw - 16px); top: 60px; }
}

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

/* --- Print --- */
@media print {
  body { background: #fff; color: #000; }
  .app-titlebar, .menubar, .toolbar, .statusbar,
  .skip-link, .dialog, .window-controls, .titlebar-buttons { display: none !important; }
  .app-window { box-shadow: none; border: none; max-width: 100%; margin: 0; }
}
