/*
 * Photo Face Fork theme — replaces theme-retro.css for the fork's settings
 * page. Neutral darkroom utility per the fork design brief: the user's
 * photography and the 64-colour watch canvas carry the visual weight, the
 * page itself is stone/charcoal with one cobalt accent. Light + dark token
 * sheets, mapped onto Pico CSS v2 variables. Load AFTER theme.css.
 */
@font-face {
  font-family: "Inter";
  src: url("../photo-face/fonts/Inter-Latin-Variable.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
/* Fork Phase 4: the Editorial Serif style specimen renders in the same
   typeface the watch now bundles (Instrument Serif, OFL). */
@font-face {
  font-family: "Instrument Serif";
  src: url("../photo-face/fonts/InstrumentSerif-Latin-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
/* Fork Phase 4 (completed): the Tall Condensed and Rounded specimens
   render in the same typefaces the watch now bundles (Barlow Condensed
   Bold and Fredoka SemiBold, both OFL). */
@font-face {
  font-family: "Barlow Condensed";
  src: url("../photo-face/fonts/BarlowCondensed-Latin-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fredoka";
  src: url("../photo-face/fonts/Fredoka-Latin-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;

  /* 4/8px Spacing Scale (brief values; override theme.css) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  /* Control Geometry */
  --tap-min: 44px;
  --radius-sm: 6px;
  --radius-md: 10px;

  /* Light Mode Palette (Neutral Base + Cobalt Accent + Semantic Success/Error) */
  --bg-page: #f7f7f5;
  --bg-surface: #efefec;
  --bg-elevated: #ffffff;
  --text-primary: #171716;       /* 15.6:1 on --bg-surface */
  --text-secondary: #52524e;     /* 6.88:1 on --bg-surface */
  --border-hairline: #dcdcd6;
  --border-input: #757570;       /* 4.55:1 on --bg-page */

  --accent: #0f5c8c;             /* 6.25:1 on --bg-surface; 7.17:1 with #ffffff */
  --accent-contrast: #ffffff;
  --accent-subtle: #e1eef6;

  --status-success: #166534;     /* 5.98:1 on --bg-surface */
  --status-success-subtle: #dcfce7;
  --status-error: #b91c1c;       /* 5.65:1 on --bg-surface */
  --status-error-subtle: #fee2e2;

  --thumb-radius: var(--radius-md);
  --button-radius: var(--radius-sm);
}

/* Pico CSS v2 Variable Mapping. Pico declares its own --pico-* values on
 * :root:not([data-theme=dark]) (light) and :root:not([data-theme]) inside
 * its dark media query, both specificity (0,2,0); a plain :root mapping
 * loses to them and Pico's default #fff page background wins. These rules
 * match that specificity and load later, so the brief's tokens actually
 * reach Pico-painted surfaces (page background, body text, form elements). */
:root:not([data-theme="dark"]) {
  --pico-font-family: var(--font-sans);
  --pico-background-color: var(--bg-page);
  --pico-color: var(--text-primary);
  --pico-muted-color: var(--text-secondary);
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-inverse: var(--accent-contrast);
  --pico-form-element-background-color: var(--bg-elevated);
  --pico-form-element-border-color: var(--border-input);
  --pico-border-radius: var(--radius-sm);
  --pico-box-shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page: #121314;
    --bg-surface: #1c1e21;
    --bg-elevated: #25282c;
    --text-primary: #f2f3f5;     /* 13.3:1 on --bg-elevated */
    --text-secondary: #a6abb4;   /* 6.41:1 on --bg-elevated */
    --border-hairline: #2e3238;
    --border-input: #8a8f98;     /* 5.20:1 on --bg-page */

    --accent: #5eb0e5;           /* 6.20:1 on --bg-elevated; 7.85:1 with #0b151e */
    --accent-contrast: #0b151e;
    --accent-subtle: #162c3b;

    --status-success: #4ade80;
    --status-success-subtle: #112a1c;
    --status-error: #f87171;
    --status-error-subtle: #311517;

    /* Pico mapping, dark (see the light rule above for why). */
    --pico-font-family: var(--font-sans);
    --pico-background-color: var(--bg-page);
    --pico-color: var(--text-primary);
    --pico-muted-color: var(--text-secondary);
    --pico-primary: var(--accent);
    --pico-primary-background: var(--accent);
    --pico-primary-inverse: var(--accent-contrast);
    --pico-form-element-background-color: var(--bg-elevated);
    --pico-form-element-border-color: var(--border-input);
    --pico-border-radius: var(--radius-sm);
    --pico-box-shadow: none;
  }
}

/* --- Type scale: hierarchy from size, weight, whitespace only ----------- */
body { font-family: var(--font-sans); }
hgroup h1, h1 {
  font-size: 20px; line-height: 1.3; font-weight: 600;
  letter-spacing: -0.015em; color: var(--text-primary);
  text-transform: none;
}
section h2 {
  font-size: 16px; line-height: 1.35; font-weight: 600;
  color: var(--text-primary); text-transform: none; letter-spacing: normal;
  margin-top: var(--space-8); margin-bottom: var(--space-3);
}
section h2::after { content: none; }   /* no stripe underline, ever */
label, .rowcap, fieldset legend {
  font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--text-primary);
}
small, .secnote, .wellhint, figcaption {
  font-size: 12px; line-height: 1.45; font-weight: 400; color: var(--text-secondary);
  text-transform: none; letter-spacing: normal;
}
#status, .num, #convtext { font-variant-numeric: tabular-nums; }
button, select, input { font-family: var(--font-sans); }

/* --- Page layout --------------------------------------------------------- */
main.fork-main { max-width: 560px; margin-inline: auto; padding-inline: var(--space-4); }
.layout { display: block; }
@media (min-width: 768px) {
  main.fork-main { max-width: 960px; }
  .layout {
    display: grid; grid-template-columns: 280px minmax(0, 1fr);
    gap: var(--space-8); align-items: start;
  }
  .stage-col { position: sticky; top: var(--space-6); }
  .stage-col .watchscale { transform: none; }
  .stage-col .bezel { width: fit-content; height: auto; }
}
section { border-top: 0; }
section + section { border-top: 0; padding-top: 0; }

/* --- Watch Preview Stage -------------------------------------------------- */
.stage-col {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg-page);
  padding-block: var(--space-2);
}
.bezel {
  background: #18191b; padding: var(--space-2);
  border: 1px solid var(--border-hairline); border-radius: var(--radius-md);
  width: fit-content; margin: 0 auto;
}
.bezel #watch { border: 0; border-radius: 10px; background: #25282c; }
.pebble-round .bezel #watch { border-radius: 50%; }
/* Compact mobile dock: the watch renders at a CSS scale so the sticky stage
   stays short; transform (not layout) so face-config.js measurements of the
   unscaled layout stay exact. The 1:1 button toggles .big. */
.watchscale { transform-origin: top left; }
@media (max-width: 767px) {
  .stage-flex { display: flex; gap: var(--space-4); align-items: flex-start; }
  .watchscale { transform: scale(0.75); }
  .bezel { width: calc(200px * 0.75 + 18px); height: calc(228px * 0.75 + 18px); }
  .pebble-round .watchscale { transform: scale(0.6); }
  .pebble-round .bezel { width: calc(260px * 0.6 + 18px); height: calc(260px * 0.6 + 18px); }
  .bezel.big .watchscale { transform: none; }
  .bezel.big { width: fit-content; height: auto; }
}
@media (min-width: 768px) { .stage-flex { display: block; } }
#nophoto {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: 12px; pointer-events: none; z-index: 0;
}
.stage-controls {
  display: flex; flex-direction: column; gap: var(--space-2);
  margin-top: var(--space-2);
}
@media (max-width: 767px) {
  .stage-controls { margin-top: 0; flex: 1; min-width: 96px; }
}
.seg { display: flex; gap: var(--space-1); }
.seg button {
  flex: 1; min-height: var(--tap-min); margin: 0; padding: var(--space-1) var(--space-2);
  font-size: 14px; font-weight: 500; border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-input);
}
.seg button.on { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.stage-controls > button.util {
  min-height: var(--tap-min); min-width: var(--tap-min); margin: 0;
  font-size: 14px; font-weight: 500; border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-input);
}
.stage-controls > button.util.on { background: var(--accent-subtle); border-color: var(--accent); color: var(--text-primary); }
/* "Show 3x3 grid": hairline cell boundaries + round safe-zone guide. */
#watch.showgrid .cells {
  background:
    linear-gradient(to right, transparent calc(33.3% - 1px), rgba(255,255,255,.45) 33.3%, transparent calc(33.3% + 1px)),
    linear-gradient(to right, transparent calc(66.6% - 1px), rgba(255,255,255,.45) 66.6%, transparent calc(66.6% + 1px)),
    linear-gradient(to bottom, transparent calc(33.3% - 1px), rgba(255,255,255,.45) 33.3%, transparent calc(33.3% + 1px)),
    linear-gradient(to bottom, transparent calc(66.6% - 1px), rgba(255,255,255,.45) 66.6%, transparent calc(66.6% + 1px));
}
.pebble-round #watch.showgrid .cells::after {
  content: ""; position: absolute; inset: 6%; border: 1px dashed rgba(255,255,255,.5);
  border-radius: 50%; pointer-events: none;
}

/* --- Sticky save bar ------------------------------------------------------- */
main.fork-main { padding-bottom: 88px; }
#savebar {
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-hairline);
  border-image: none; box-shadow: none;
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  z-index: 30;
}
#savebar #save, #savebar #discard { min-height: var(--tap-min); font-size: 14px; font-weight: 500; }
#savebar #discard { color: var(--text-secondary); border: 1px solid var(--border-input); background: transparent; }

/* --- Look presets + curated palettes --------------------------------------- */
.presetrow, .paletterow { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); }
.preset {
  min-height: var(--tap-min); margin: 0; padding: var(--space-2) var(--space-3);
  font-size: 14px; font-weight: 500; border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-input); cursor: pointer; width: auto;
}
.preset:active { background: var(--accent-subtle); }
.palettebtn {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: var(--tap-min); margin: 0; padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  font-size: 14px; font-weight: 500; border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-input); cursor: pointer; width: auto;
}
.palettebtn .duo { display: flex; width: 44px; height: 32px; border-radius: var(--radius-sm); overflow: hidden; flex: none; }
.palettebtn .duo span { flex: 1; }

/* --- All-64 drawer ------------------------------------------------------------ */
#all64 { margin: var(--space-3) 0 var(--space-4); }
#all64 summary { min-height: var(--tap-min); display: flex; align-items: center; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--text-primary); }
#grid64 { display: grid; grid-template-columns: repeat(8, 44px); gap: var(--space-1); margin-top: var(--space-2); }
#grid64 button {
  width: 44px; height: 44px; margin: 0; padding: 0; border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline); cursor: pointer;
}
#grid64 button.on { outline: 2px solid var(--text-primary); outline-offset: 0;
  box-shadow: inset 0 0 0 2px var(--bg-elevated); }
#drawertarget { margin-top: var(--space-2); max-width: 280px; }

/* --- Clock style families ----------------------------------------------------- */
.fontgroup { margin: 0 0 var(--space-4); }
.fontgroup h3 {
  font-size: 12px; line-height: 1.45; font-weight: 500; color: var(--text-secondary);
  margin: 0 0 var(--space-2); text-transform: none; letter-spacing: normal;
}
.fontgrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
@media (min-width: 768px) { .fontgrid { grid-template-columns: 1fr 1fr 1fr; } }

/* --- 3x3 spatial map ------------------------------------------------------------ */
#map3x3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-1);
  max-width: 300px; margin: 0 0 var(--space-3); }
#map3x3 .mapcell {
  min-height: 44px; background: var(--bg-surface); border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm); padding: var(--space-1);
  font-size: 12px; line-height: 1.45; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; text-align: center;
}
#map3x3 .mapcell.on { color: var(--text-primary); border-color: var(--accent); background: var(--accent-subtle); }

/* --- Empty / progress / error states --------------------------------------------- */
.emptygal {
  background: var(--bg-surface); padding: var(--space-6); border-radius: var(--radius-md);
  margin: 0 0 var(--space-3); grid-column: 1 / -1;
}
.emptygal p { margin: 0 0 var(--space-3); color: var(--text-primary); font-size: 14px; }
.emptygal button { min-height: var(--tap-min); margin: 0; width: auto; }
#conv { margin: var(--space-3) 0; }
#conv progress { width: 100%; }
#conv p { margin: var(--space-1) 0 0; font-size: 12px; color: var(--text-secondary); }
#errbanner {
  background: var(--status-error-subtle); border-left: 3px solid var(--status-error);
  padding: var(--space-3); margin: var(--space-3) 0; font-size: 14px; color: var(--text-primary);
}
#gridwarn { font-size: 12px; color: var(--text-secondary); margin: var(--space-2) 0 0; }

/* --- Edit Photo modal sheet --------------------------------------------------------- */
.editoverlay {
  position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.editsheet {
  background: var(--bg-elevated); color: var(--text-primary);
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: var(--radius-md) var(--radius-md) 0 0; padding: var(--space-4);
}
.editsheet h3 { font-size: 16px; font-weight: 600; margin: 0 0 var(--space-3); }
.editsheet .editbtns { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-4); }
.editsheet .editbtns button { min-height: var(--tap-min); margin: 0; font-size: 14px; font-weight: 500; }
.editsheet .editbtns .danger { color: var(--status-error); background: transparent; border: 1px solid var(--border-input); }
.thumbbtn {
  display: block; width: 100%; margin: 0; padding: 0; background: none; border: 0;
  cursor: pointer; position: relative; border-radius: var(--thumb-radius);
}
.ovdot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); pointer-events: none;
}
body.fonts-loading .fontchip .t { opacity: .5; }
