/* Tidewater: the platform's design tokens and base styles. See docs/design/tidewater.md.
   Pages use the tokens below, never raw colour values.
   Dark is the default. Light follows prefers-color-scheme; <html data-theme="light|dark"> overrides it. */

:root {
  color-scheme: dark;
  --bg: #0e131b;
  --bg-glow: #1c2b3a;
  --surface: #141c27;
  --surface-2: #16202c;
  --line: #223042;
  --line-soft: #1a2532;
  /* The edge of a control (field, select, button): about 3:1 against the surface it sits on. */
  --line-strong: #5f7086;
  --text: #d6dce6;
  --text-muted: #8b98ab;
  --text-faint: #7a889c;
  --title: #f1e9d6;
  --accent: #7fd1c7;
  --accent-bg: #173634;
  /* Brighter accent: text on an accent-bg pill, the brightest grains of arcane dust. */
  --accent-bright: #bdeee8;
  --neutral-bg: #1d2633;
  --danger: #e07a6f;
  --warning: #e0b56f;
  /* Text on a filled accent button. */
  --on-accent: #0e131b;
  /* Regions on a map: an amber of their own, apart from the teal accent. */
  --region: #e8b04a;
  --region-bg: #3a2c10;
  --region-text: #f3d9a3;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;

  /* Type scale: 16 px body, titles about 1.6 to 1.8 times body. */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.6rem;
  --text-2xl: 1.8rem;
  /* Page titles of the world pages (Images, Maps, Templates, Setup ...). */
  --text-3xl: 2.125rem;
  --leading: 1.6;
  --measure: 70ch;

  /* Spacing: an 8 px rhythm. */
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;

  /* The top bar: one height and one wordmark size on every page (chooser, world, account, privacy). */
  --header-h: 60px;
  --wordmark-size: 14px;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 14px;
  --focus: 2px solid var(--accent);
  --motion: 180ms ease-out;
}

@media (max-width: 700px) {
  :root { --header-h: 56px; }
}

/* Light mode keeps the same character: pale sea-grey, white surfaces, slate text, ink titles, deeper teal. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6f8;
    --bg-glow: #e3ecf1;
    --surface: #ffffff;
    --surface-2: #eef2f5;
    --line: #d5dde5;
    --line-soft: #e4e9ee;
    --line-strong: #7b8a9c;
    --text: #1f2a37;
    --text-muted: #4f5d6f;
    --text-faint: #5e6c80;
    --title: #16202c;
    --accent: #17756c;
    --accent-bg: #dcf0ed;
    --accent-bright: #145f58;
    --neutral-bg: #e8edf2;
    --danger: #b3473d;
    --warning: #8a5a12;
    --on-accent: #ffffff;
    --region: #b9801a;
    --region-bg: #fbefd2;
    --region-text: #6b4a0a;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --bg-glow: #e3ecf1;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --line: #d5dde5;
  --line-soft: #e4e9ee;
  --line-strong: #7b8a9c;
  --text: #1f2a37;
  --text-muted: #4f5d6f;
  --text-faint: #5e6c80;
  --title: #16202c;
  --accent: #17756c;
  --accent-bg: #dcf0ed;
  --accent-bright: #145f58;
  --neutral-bg: #e8edf2;
  --danger: #b3473d;
  --warning: #8a5a12;
  --on-accent: #ffffff;
  --region: #b9801a;
  --region-bg: #fbefd2;
  --region-text: #6b4a0a;
}

/* Base */

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

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

/* Scrollbars: thin, in the control edge colour, everywhere (menus, lists, dialogs). */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  color: var(--text);
  background-color: var(--bg);
  /* The faint light from above. */
  background-image: radial-gradient(1100px 520px at 50% -12%, var(--bg-glow), var(--bg) 70%);
  background-repeat: no-repeat;
}

h1, h2, h3, .title {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--title);
  line-height: 1.25;
  margin: 0 0 var(--space-2);
}
h1, .title { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { margin: 0 0 var(--space-3); }

.prose { max-width: var(--measure); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }

hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-4) 0; }

::selection { background: var(--accent-bg); color: var(--text); }

/* Focus: a visible 2 px accent outline on every interactive element. */
:focus-visible { outline: var(--focus); outline-offset: 2px; }

/* Elements with the hidden attribute stay hidden, whatever their display rule. */
[hidden] { display: none !important; }

/* Text helpers */

.muted { color: var(--text-muted); }
.faint, .caption { color: var(--text-faint); font-size: var(--text-sm); }
.breadcrumb { color: var(--text-faint); font-size: var(--text-sm); }
.breadcrumb a { color: var(--text-faint); }
.breadcrumb a:hover { color: var(--accent); }
.error { color: var(--danger); }
.warning { color: var(--warning); }
.empty { color: var(--text-muted); }
/* Hidden on screen, still read out. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Panels, boxes and dialogs: radius 8, 1 px line, surface fill, no shadow. */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
}

dialog {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }

/* Labels and pills: small, sentence case, fully rounded. */

.pill, .label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text-muted);
  background: var(--neutral-bg);
}
.label-accent, .pill-accent { color: var(--accent); background: var(--accent-bg); }
.label-danger { color: var(--danger); }
.label-warning { color: var(--warning); }

/* Form fields and labels */

label { display: block; margin: 0 0 4px; color: var(--text-muted); font-size: var(--text-sm); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  max-width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* Selects: our own chevron (two gradients, so it follows the theme) in place of the browser's. The open list is
   drawn by the browser, in the page's colour scheme. Label pills (.doc-label-input) draw their own. */
select:not(.doc-label-input) {
  appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 55%, calc(100% - 14px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select:not(.doc-label-input):hover:not(:disabled) { border-color: var(--accent); }
select option { background: var(--surface); color: var(--text); }

/* Colour inputs: a round swatch with a theme border. The picker that opens is the browser's. */
input[type="color"] {
  appearance: none;
  width: 36px;
  height: 36px;
  padding: 3px;
  border-radius: 50%;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
input[type="color"]:hover { border-color: var(--accent); }

/* A colour field: the swatch and its hex code side by side. */
.color-field { display: inline-flex; align-items: center; gap: var(--space-1); }
.color-field input[type="text"] { width: 11ch; max-width: 11ch; padding: 6px 10px; font-family: var(--font-mono); font-size: var(--text-sm); }
input[type="search"], .search { border-radius: var(--radius-pill); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); padding: 0; }
input[type="file"] { color: var(--text-muted); padding: 0; border: 0; background: none; }
/* The file button looks like every other button. */
input[type="file"]::file-selector-button {
  margin-right: var(--space-2);
  padding: 6px 14px;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); }

/* Buttons: quiet by default, one accent for the primary action, danger only for destructive ones. */

button, .button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1.4;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--motion), border-color var(--motion), color var(--motion), transform 100ms ease-out;
}
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
/* Pressed: a small push in. */
button:active:not(:disabled), .button:active:not([aria-disabled="true"]) { transform: scale(0.97); }
button:disabled, .button[aria-disabled="true"] { opacity: 0.6; cursor: default; }

.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.primary:hover { background: var(--accent); color: var(--on-accent); filter: brightness(1.08); }

.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.danger:hover { border-color: var(--danger); background: var(--surface-2); }

button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
}
button.link:hover { text-decoration: underline; }

/* The account control, the same on every page with a top bar: the avatar (the first letter of the name) and
   "Account". On phones the label is read out but not shown, and the control is a 44 px tap target. */
.account { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 4px; color: var(--text-muted); font-size: 13px; border-radius: 999px; white-space: nowrap; }
.account:hover { color: var(--text); text-decoration: none; }
.account[aria-current="page"] { color: var(--text); }
.avatar { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--neutral-bg); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.account:hover .avatar, .account[aria-current="page"] .avatar { color: var(--text); }
@media (max-width: 600px) {
  .account { min-width: 44px; min-height: 44px; justify-content: center; }
  .account-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* Menu sigils: 24x24 symbols drawn with 1.5 strokes in the current text colour.

   Use: <svg class="sigil" width="16" height="16" aria-hidden="true"><use href="/menu-sigils.svg#sigil-world"/></svg> */
.sigil {
  display: inline-block;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Hover: the sigil draws itself in once (0.55 s). Apply .menu-item to any container of a .sigil. */
.menu-item:hover .sigil * { stroke-dasharray: 80; animation: sigil-draw 0.55s ease-out; }
@keyframes sigil-draw { from { stroke-dashoffset: 80; } to { stroke-dashoffset: 0; } }

/* Motion is reduced when the user asks for it. */
@media (prefers-reduced-motion: reduce) {
  .menu-item:hover .sigil * { animation: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
