/* The Cartographer's Last Expedition — carries the palette of the printed pack. */

:root {
  --ink: #1a2e3b;
  --ink-soft: #3d566604;
  --sea: #2e6f8e;
  --sea-dark: #1f5670;
  --sand: #f4ede0;
  --sand-light: #fbf7f0;
  --rule: #c9b79a;
  --green: #e8f2ea;
  --green-line: #4e8c5e;
  --amber: #fbf0dc;
  --amber-line: #b8862b;
  --paper: #fffdf9;
  --shadow: 0 1px 2px rgba(26,46,59,.06), 0 4px 16px rgba(26,46,59,.07);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 39h40M39 0v40' stroke='%231a2e3b' stroke-opacity='.035' stroke-width='1'/%3E%3C/svg%3E");
  line-height: 1.55; font-size: 17px;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 2.1rem; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .9em; }
a { color: var(--sea); }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 20px 90px; }
.wrap-wide { max-width: 1180px; }

/* ---------------------------------------------------------------- header -- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,253,249,.93); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar-in { max-width: 860px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 14px; }
.topbar-in.wide { max-width: 1180px; }
.brand { font-size: .72rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sea); font-weight: 700; text-decoration: none; }
.spacer { flex: 1; }
.who { font-size: .8rem; color: var(--sea); }

.eyebrow { font-size: .72rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sea); font-weight: 700; margin-bottom: 6px; }
.pagehead { border-bottom: 2px solid var(--rule); padding: 28px 0 10px; margin-bottom: 6px; }
.subtitle { font-style: italic; color: var(--sea); margin-bottom: 28px; }

/* ---------------------------------------------------------------- panels -- */
.panel { background: var(--sand); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 18px 20px; margin: 22px 0; }
.panel-light { background: var(--sand-light); }
.panel-quote { background: var(--sand-light); font-style: italic; }
.panel h3 { font-size: .72rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sea); margin-bottom: 10px; }
.panel.brief p { font-style: italic; }
.panel > :last-child { margin-bottom: 0; }

.panel-ok { background: var(--green); border-color: var(--green-line); }
.panel-ok h3 { color: var(--green-line); }
.panel-no { background: var(--amber); border-color: var(--amber-line); }
.panel-no h3 { color: var(--amber-line); }

.section { margin: 34px 0 10px; display: flex; gap: 10px; align-items: baseline; }
.section .num { color: var(--sea); font-weight: 700; }
.section h2 { margin: 0; font-size: 1.2rem; }

/* --------------------------------------------------------------- buttons -- */
button { font: inherit; }
.btn {
  background: var(--sea); color: #fff; border: 0; border-radius: 8px;
  padding: 11px 20px; font-weight: 600; cursor: pointer; font-size: .95rem;
  transition: background .15s, transform .06s;
}
.btn:hover { background: var(--sea-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: #b9c6cd; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--sea); border: 1px solid var(--rule); }
.btn-ghost:hover { background: var(--sand); color: var(--sea-dark); }
.btn-sm { padding: 10px 14px; font-size: .85rem; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 16px 0; }

/* ---------------------------------------------------------------- inputs -- */
input[type=text], input[type=password], textarea, select {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--rule); border-radius: 7px; padding: 8px 10px;
}
input[type=text]:focus, textarea:focus, input[type=password]:focus {
  outline: 2px solid var(--sea); outline-offset: -1px; border-color: var(--sea);
}
textarea { width: 100%; min-height: 100px; resize: vertical; line-height: 1.6; }
.inp-frac { width: 5.5em; text-align: center; font-size: 1.05rem; }
.inp-num { width: 3.4em; text-align: center; }
/* Default radios land at 13px — too small for a nine-year-old on a tablet. */
input[type=radio], input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--sea); }
.field { margin: 14px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint-inline { font-size: .84rem; color: var(--sea); font-style: italic; }

/* ---------------------------------------------------------------- tables -- */
table { border-collapse: collapse; width: 100%; margin: 16px 0; background: #fff; }
th, td { border: 1px solid var(--rule); padding: 9px 11px; text-align: center; }
th { background: var(--sea); color: #fff; font-weight: 600; font-size: .88rem; }
tbody tr:nth-child(odd) td { background: var(--sand-light); }
td.l, th.l { text-align: left; }
.frac-cell { font-size: 1.15rem; font-weight: 600; }
.tablescroll { overflow-x: auto; }

/* row status after a check */
tr.row-flag td { background: var(--amber) !important; }
tr.row-good td { background: var(--green) !important; }

/* ------------------------------------------------------------ shade grid -- */
.shadegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  max-width: 460px; margin: 20px auto; }
.shadecell {
  aspect-ratio: 1.35 / 1; border: 2px solid var(--ink); border-radius: 8px;
  background: #fff; font-size: 1.25rem; font-weight: 600; color: var(--ink);
  cursor: pointer; display: grid; place-items: center; user-select: none;
  transition: background .12s, transform .06s;
}
.shadecell:hover { background: var(--sand-light); }
.shadecell[aria-pressed="true"] { background: var(--sea); color: #fff; border-color: var(--sea-dark); }
.shadecell:active { transform: scale(.97); }

/* ------------------------------------------------------------ number line -- */
.trail { margin: 26px 0 10px; }
.trailtray {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px;
  background: var(--sand-light); border: 1px dashed var(--rule);
  border-radius: var(--radius); min-height: 72px; align-items: center;
}
.trailtray.over { border-color: var(--sea); background: var(--sand); }
.trailtray:focus-visible, .linebox:focus-visible, .slot:focus-visible {
  outline: 3px solid var(--sea); outline-offset: 2px;
}
.traylabel { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--sea); font-weight: 700; margin: 18px 0 8px; }

.pin {
  background: var(--sand); border: 2px solid var(--ink); border-radius: 999px;
  padding: 10px 14px; font-size: .9rem; font-weight: 600; cursor: grab;
  white-space: nowrap; box-shadow: var(--shadow); touch-action: none;
  min-height: 44px; display: inline-flex; align-items: center;
}
.pin:active { cursor: grabbing; }
/* --drop is set by numberLine(): how far this pin sits above the axis, so the
   leader line still reaches it once pins are stacked out of each other's way. */
.pin.placed { position: absolute; bottom: 26px; transform: translateX(-50%); z-index: 2; --drop: 26px; }
.pin.placed::after {
  content: ''; position: absolute; left: 50%; bottom: calc(-1 * var(--drop));
  width: 2px; height: var(--drop); background: var(--ink); opacity: .35;
}
.pin .pv { color: var(--sea); font-weight: 700; margin-left: 5px; }

.linebox { position: relative; height: 150px; margin: 10px 0 6px;
  border-bottom: 3px solid var(--ink); }
.linebox.over { background: rgba(46,111,142,.05); }
.tick { position: absolute; bottom: -3px; width: 2px; height: 15px; background: var(--ink); }
.ticklabel { position: absolute; bottom: -30px; transform: translateX(-50%);
  font-weight: 700; font-size: .92rem; white-space: nowrap; }
.linescale { height: 34px; }

/* ------------------------------------------------------------ code boxes -- */
.codeboxes { display: flex; gap: 10px; justify-content: center; margin: 22px 0; flex-wrap: wrap; }
.codeboxes input {
  width: 62px; height: 76px; text-align: center; font-size: 2rem; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 10px; background: #fff; padding: 0;
}
.codeboxes input:focus { outline: 3px solid var(--sea); outline-offset: -2px; }

/* ----------------------------------------------------------- order slots -- */
.slots { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0; }
.slot {
  flex: 1 1 130px; min-height: 96px; border: 2px dashed var(--rule); border-radius: var(--radius);
  display: grid; place-items: center; padding: 8px; background: var(--sand-light); text-align: center;
}
.slot.over { border-color: var(--sea); background: var(--sand); }
.slot.filled { border-style: solid; border-color: var(--ink); background: #fff; }
.slotcap { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--sea); }
.chip {
  background: var(--sand); border: 2px solid var(--ink); border-radius: 8px;
  padding: 8px 12px; cursor: grab; touch-action: none; box-shadow: var(--shadow);
}
.chip .letter { font-size: 1.5rem; font-weight: 700; display: block; }
.chip .val { font-size: .85rem; color: var(--sea); font-weight: 600; }

/* ------------------------------------------------------------- fragments -- */
.fragcard {
  background: var(--sand); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: 20px; text-align: center; box-shadow: var(--shadow);
}
.fragcard .cap { font-size: .7rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sea); font-weight: 700; }
.fragcard .letter { font-size: 3.4rem; font-weight: 700; line-height: 1.05; margin: 4px 0; }
.fragcard .val { font-size: 1.5rem; font-weight: 700; color: var(--sea); }
.fragcard .from { font-size: .8rem; font-style: italic; margin-top: 6px; }
.fragcard.locked { background: #f2f0ec; border-style: dashed; border-color: var(--rule); color: #9aa6ad; }
.fragcard.locked .letter { color: #c8d0d5; }

.fraggrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 20px 0; }

/* ----------------------------------------------------------------- cards -- */
.lessongrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin: 24px 0; }
.lessoncard {
  display: block; text-decoration: none; color: inherit; background: #fff;
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s;
}
.lessoncard:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(26,46,59,.12); }
.lessoncard .n { font-size: .72rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--sea); font-weight: 700; }
.lessoncard h3 { margin: 4px 0 4px; font-size: 1.12rem; }
.lessoncard .c { font-size: .88rem; color: #5b6b75; }
.lessoncard .status { margin-top: 10px; font-size: .82rem; font-weight: 600; }
.lessoncard.done { border-color: var(--green-line); }
.lessoncard.done .status { color: var(--green-line); }
.lessoncard.locked { opacity: .55; pointer-events: none; }

/* ---------------------------------------------------------------- reveal -- */
.reveal { margin: 18px 0; }
.reveal-body { background: var(--amber); border: 1px solid var(--amber-line);
  border-radius: var(--radius); padding: 16px 18px; margin-top: 10px; }
.reveal-body h4 { margin: 0 0 6px; font-size: .72rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--amber-line); }
.gatehint { font-size: .84rem; color: #6d7c85; font-style: italic; }

/* ---------------------------------------------------------------- misc ---- */
.pill { display: inline-block; background: var(--sand); border: 1px solid var(--rule);
  border-radius: 999px; padding: 3px 11px; font-size: .78rem; font-weight: 600; }
.pill.ok { background: var(--green); border-color: var(--green-line); color: var(--green-line); }
.pill.no { background: var(--amber); border-color: var(--amber-line); color: var(--amber-line); }
.mono { font-family: var(--mono); letter-spacing: .18em; font-weight: 700; }
.riddle { background: var(--ink); color: #fff; border-radius: var(--radius);
  padding: 30px 26px; text-align: center; margin: 26px 0; }
.riddle p { font-style: italic; font-size: 1.22rem; margin: 0 0 6px; }
.riddle .sig { font-size: .85rem; opacity: .75; margin-top: 14px; font-style: normal; }
.vc { font-size: .78rem; color: var(--sea); font-style: italic;
  border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 40px; }
.center { text-align: center; }
.muted { color: #6d7c85; }
.big { font-size: 1.6rem; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 90; font-size: .9rem; }

dialog { border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 26px; max-width: 440px; width: calc(100% - 40px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(26,46,59,.45); }

@media (max-width: 620px) {
  body { font-size: 16px; }
  h1 { font-size: 1.65rem; }
  .shadecell { font-size: 1.05rem; }
  .codeboxes input { width: 50px; height: 62px; font-size: 1.5rem; }
  .linebox { height: 190px; }
}

@media print {
  .topbar, .btnrow, .reveal { display: none; }
  body { background: #fff; }
}
