/* ============================================================
   NOSTOS — the last summers of the Bronze Age
   The world dims act by act. All color lives in these variables.
   ============================================================ */

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;

  /* Act 1 — high summer of the world */
  --sky-hi: #dcd2b4;
  --sky-lo: #cbb98d;
  --sea-hi: #3c5d80;
  --sea-lo: #22364f;
  --sun: #f2e2b0;
  --sun-glow: rgba(242, 226, 176, 0.55);
  --card-bg: rgba(244, 236, 218, 0.97);
  --card-ink: #2c2620;
  --card-ink-soft: #5d5347;
  --card-edge: rgba(120, 96, 60, 0.35);
  --accent: #a8542f;
  --accent-soft: #b98a4a;
  --gold: #b98a4a;
  --bar-bg: rgba(34, 30, 24, 0.82);
  --bar-ink: #e6dcc4;
  --btn-bg: rgba(255, 252, 244, 0.55);
  --btn-bg-hover: rgba(184, 118, 66, 0.16);
  --hint-ink: #8a7a5f;
  --tex-opacity: 0.05;
}

body[data-act="2"] {
  --sky-hi: #c8b28a;
  --sky-lo: #b08d5e;
  --sea-hi: #375070;
  --sea-lo: #1d2c42;
  --sun: #e8c176;
  --sun-glow: rgba(226, 180, 106, 0.4);
  --card-bg: rgba(238, 227, 203, 0.96);
  --card-ink: #2b2520;
  --accent: #9c4a2b;
}

body[data-act="3"] {
  --sky-hi: #7d6a63;
  --sky-lo: #8f6752;
  --sea-hi: #2c3a55;
  --sea-lo: #131c2e;
  --sun: #cf8352;
  --sun-glow: rgba(200, 122, 74, 0.3);
  --card-bg: rgba(48, 42, 40, 0.93);
  --card-ink: #e2d6bc;
  --card-ink-soft: #b3a68c;
  --card-edge: rgba(190, 160, 110, 0.25);
  --accent: #cf8352;
  --gold: #c99a58;
  --btn-bg: rgba(30, 26, 24, 0.4);
  --btn-bg-hover: rgba(207, 131, 82, 0.14);
  --hint-ink: #97896f;
  --tex-opacity: 0.07;
}

body[data-act="4"] {
  --sky-hi: #3a3947;
  --sky-lo: #4b3a44;
  --sea-hi: #1d2638;
  --sea-lo: #0a0e18;
  --sun: #8f5347;
  --sun-glow: rgba(143, 83, 71, 0.22);
  --card-bg: rgba(32, 28, 30, 0.94);
  --card-ink: #ddd0b6;
  --card-ink-soft: #a2957c;
  --card-edge: rgba(180, 150, 105, 0.22);
  --accent: #b4614b;
  --gold: #b98d55;
  --btn-bg: rgba(20, 17, 19, 0.45);
  --btn-bg-hover: rgba(180, 97, 75, 0.16);
  --hint-ink: #8d8069;
  --tex-opacity: 0.08;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--serif);
  color: var(--card-ink);
  overflow-x: hidden;
  background: var(--sea-lo);
}

/* ---------- the sky, the sun, the sea ---------- */

#sky {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(var(--sky-hi) 0%, var(--sky-lo) 62%, var(--sea-hi) 62.2%, var(--sea-lo) 100%);
  transition: background 9s ease;
}

#sky .sun {
  position: absolute;
  left: 50%; top: 38%;
  width: min(34vmin, 300px); height: min(34vmin, 300px);
  margin-left: min(-17vmin, -150px);
  border-radius: 50%;
  background: radial-gradient(circle, var(--sun) 0%, var(--sun) 34%, transparent 72%);
  box-shadow: 0 0 120px 60px var(--sun-glow);
  opacity: 0.85;
  transition: top 12s ease, background 9s ease, box-shadow 9s ease, opacity 9s ease;
}
body[data-act="2"] #sky .sun { top: 47%; }
body[data-act="3"] #sky .sun { top: 55%; opacity: 0.7; }
body[data-act="4"] #sky .sun { top: 60%; opacity: 0.45; }

#sky .sea {
  position: absolute; left: 0; right: 0; top: 62%; bottom: 0;
  background:
    repeating-linear-gradient(178deg,
      transparent 0 26px,
      rgba(255, 255, 255, 0.035) 26px 27px,
      transparent 27px 54px);
  animation: swell 14s ease-in-out infinite alternate;
}
@keyframes swell {
  from { transform: translateY(0); opacity: 0.8; }
  to   { transform: translateY(6px); opacity: 1; }
}

#sky .grain-tex {
  position: absolute; inset: 0;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2"/><feColorMatrix type="saturate" values="0"/></filter><rect width="240" height="240" filter="url(%23n)" opacity="0.55"/></svg>');
  opacity: var(--tex-opacity);
  mix-blend-mode: multiply;
  transition: opacity 9s ease;
  pointer-events: none;
}

/* ---------- chrome ---------- */

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0.55rem 1rem 0.5rem;
  background: linear-gradient(rgba(10, 10, 14, 0.35), transparent);
  color: var(--bar-ink);
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
#topbar .brand {
  font-size: 0.8rem; letter-spacing: 0.45em; opacity: 0.75; font-weight: 400;
}
#topbar .date { text-align: center; }
#topbar #date-line {
  display: block; font-variant: small-caps; letter-spacing: 0.18em; font-size: 0.95rem;
}
#topbar .epithet {
  display: block; font-style: italic; font-size: 0.75rem; opacity: 0.75; letter-spacing: 0.04em;
}
#topbar .controls { display: flex; gap: 0.4rem; }
.icon-btn {
  background: none; border: 1px solid rgba(230, 220, 196, 0.35); border-radius: 50%;
  width: 1.9rem; height: 1.9rem; color: var(--bar-ink); cursor: pointer;
  font-size: 0.9rem; line-height: 1; opacity: 0.8; transition: opacity 0.3s, background 0.3s;
}
.icon-btn:hover { opacity: 1; background: rgba(230, 220, 196, 0.12); }
.icon-btn.on { background: rgba(230, 220, 196, 0.22); opacity: 1; }

#status {
  position: fixed; top: 3.2rem; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; gap: 1.1rem; flex-wrap: wrap; justify-content: center;
  padding: 0.4rem 1.1rem;
  background: var(--bar-bg); color: var(--bar-ink);
  border-radius: 2rem;
  border: 1px solid rgba(230, 220, 196, 0.16);
  font-size: 0.9rem;
  transition: background 4s ease;
}
#status .stat { display: inline-flex; align-items: center; gap: 0.35rem; }
#status .stat svg { width: 0.95em; height: 0.95em; fill: var(--bar-ink); stroke: var(--bar-ink); opacity: 0.8; }
#status .stat b { font-weight: 400; font-variant-numeric: tabular-nums; }
#status .stat.dim { opacity: 0.75; }
#status .stat .delta { font-size: 0.72rem; margin-left: 0.15rem; opacity: 0.9; }
.delta.up { color: #a9c17f; }
.delta.down { color: #d08a72; }

/* ---------- main column ---------- */

#app {
  max-width: 660px;
  margin: 0 auto;
  padding: 7.5rem 1.25rem 9.5rem;
  min-height: 100vh;
}

.card {
  background: var(--card-bg);
  color: var(--card-ink);
  border: 1px solid var(--card-edge);
  border-radius: 4px;
  padding: 2.2rem 2.4rem 2rem;
  box-shadow: 0 12px 40px rgba(8, 10, 18, 0.28);
  animation: rise 0.9s ease both;
  transition: background 6s ease, color 6s ease, border-color 6s ease;
  position: relative;
}
.card + .card { margin-top: 1.2rem; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* meander band along the card's top edge */
.card::before {
  content: "";
  position: absolute; top: 7px; left: 14px; right: 14px; height: 8px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="8" viewBox="0 0 24 8"><path d="M0 7h4V3h8v2H8v2h8V1H4v2H0" fill="none" stroke="%23a88a58" stroke-width="1"/></svg>');
  background-repeat: repeat-x;
  opacity: 0.5;
}

.card h1, .card h2 {
  font-weight: 400;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  margin-bottom: 1.1rem;
  font-size: 1.35rem;
  color: var(--card-ink);
}
.card h1 { font-size: 2.4rem; letter-spacing: 0.3em; text-align: center; }

.card p {
  line-height: 1.75;
  font-size: 1.02rem;
  margin-bottom: 1rem;
  color: var(--card-ink);
}
.card p:last-child { margin-bottom: 0; }
.card .soft { color: var(--card-ink-soft); font-style: italic; }
.card .result {
  border-left: 2px solid var(--accent);
  padding-left: 1rem;
  margin-top: 1.4rem;
  animation: rise 0.9s ease both;
}
.card .forecast {
  font-style: italic; font-size: 0.92rem; color: var(--card-ink-soft);
  border-top: 1px dashed var(--card-edge); margin-top: 1.3rem; padding-top: 0.9rem;
}
.card .forecast::before { content: "the scouts say — "; font-variant: small-caps; font-style: normal; letter-spacing: 0.1em; }

/* ---------- choices ---------- */

.choices { margin-top: 1.6rem; display: flex; flex-direction: column; gap: 0.65rem; }

.choice, .btn {
  font-family: var(--serif);
  text-align: left;
  background: var(--btn-bg);
  color: var(--card-ink);
  border: 1px solid var(--card-edge);
  border-radius: 3px;
  padding: 0.8rem 1.1rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.35s, border-color 0.35s, transform 0.15s;
  line-height: 1.45;
}
.choice:hover, .btn:hover { background: var(--btn-bg-hover); border-color: var(--accent); }
.choice:active { transform: translateY(1px); }
.choice .hint, .work .hint {
  display: block;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--hint-ink);
  margin-top: 0.3rem;
}
.btn.primary {
  text-align: center;
  font-variant: small-caps;
  letter-spacing: 0.2em;
  border-color: var(--accent);
  margin-top: 1.4rem;
  width: 100%;
}
.btn.quiet { border-color: transparent; opacity: 0.7; font-size: 0.85rem; text-align: center; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: var(--btn-bg); border-color: var(--accent); }

/* ---------- works (season labor) ---------- */

.works-head {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1rem;
}
.works-head .hands-left { font-variant: small-caps; letter-spacing: 0.15em; font-size: 0.85rem; color: var(--card-ink-soft); }

.works { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
@media (max-width: 560px) { .works { grid-template-columns: 1fr; } }

.work {
  position: relative;
  background: var(--btn-bg);
  border: 1px solid var(--card-edge);
  border-radius: 3px;
  padding: 0.75rem 0.95rem;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--card-ink);
  text-align: left;
  font-size: 0.98rem;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
  line-height: 1.4;
}
.work:hover { border-color: var(--accent); }
.work.picked {
  border-color: var(--accent);
  background: var(--btn-bg-hover);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.work.picked::after {
  content: "◈"; position: absolute; top: 0.5rem; right: 0.7rem; color: var(--accent); font-size: 0.8rem;
}
.work:disabled { opacity: 0.38; cursor: default; }
.work .title { display: block; }

/* ---------- resolution notes ---------- */

.notes { list-style: none; margin-top: 0.4rem; }
.notes li {
  padding: 0.45rem 0;
  line-height: 1.6;
  border-bottom: 1px solid color-mix(in srgb, var(--card-edge) 45%, transparent);
  font-size: 0.98rem;
}
.notes li:last-child { border-bottom: none; }
.notes .num { font-variant: small-caps; letter-spacing: 0.1em; font-size: 0.78rem; color: var(--hint-ink); margin-left: 0.5rem; white-space: nowrap; }

/* ---------- title & epilogue ---------- */

.title-card { text-align: center; padding-top: 3rem; padding-bottom: 3rem; }
.title-card .gk { font-size: 3rem; letter-spacing: 0.5em; text-indent: 0.5em; margin-bottom: 0.2rem; }
.title-card .sub { font-style: italic; color: var(--card-ink-soft); margin-bottom: 2.2rem; }
.title-card .hookline { max-width: 26em; margin: 0 auto 2.2rem; }

.name-input {
  font-family: var(--serif);
  font-size: 1.2rem;
  text-align: center;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--card-edge);
  color: var(--card-ink);
  padding: 0.4rem 1rem;
  width: 14em; max-width: 80%;
  outline: none;
  transition: border-color 0.3s;
}
.name-input:focus { border-color: var(--accent); }
.name-input::placeholder { color: var(--hint-ink); font-style: italic; }

.epilogue h2 { margin-top: 2.2rem; font-size: 1.05rem; color: var(--gold); }
.epilogue h2:first-of-type { margin-top: 0; }
.epilogue .litany { list-style: none; margin: 1rem 0; }
.epilogue .litany li { padding: 0.3rem 0; font-style: italic; color: var(--card-ink-soft); }
.epilogue .litany li::before { content: "— "; color: var(--gold); font-style: normal; }
.epilogue .closing { margin-top: 2rem; text-align: center; font-style: italic; }

/* ---------- the loom ---------- */

#loomwrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 0.5rem 0 0;
  background: linear-gradient(transparent, rgba(8, 9, 14, 0.55) 60%);
  text-align: center;
  pointer-events: none;
}
.loom-label {
  font-variant: small-caps; letter-spacing: 0.3em; font-size: 0.62rem;
  color: rgba(230, 220, 196, 0.55);
  margin-bottom: 0.2rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
#loom {
  display: block;
  width: 100%; height: 48px;
  opacity: 0.96;
}

/* epilogue: the loom shown large inside the card */
.shroud { width: 100%; border: 1px solid var(--card-edge); margin: 1rem 0; display: block; }

/* ---------- overlays: the hall menu & the pilot's counsel ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(9, 10, 16, 0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 1.2rem;
  animation: ovfade 0.35s ease both;
}
@keyframes ovfade { from { opacity: 0; } to { opacity: 1; } }

.overlay .ov-card {
  max-width: 660px; width: 100%;
  max-height: min(88vh, 88dvh);
  overflow-y: auto;
  animation: rise 0.45s ease both;
}
.overlay .menu-card { max-width: 420px; }

.ov-close {
  position: absolute; top: 0.9rem; right: 0.9rem; z-index: 2;
  background: none; border: 1px solid var(--card-edge); border-radius: 50%;
  width: 1.9rem; height: 1.9rem; color: var(--card-ink-soft); cursor: pointer;
  font-size: 0.8rem; line-height: 1;
  transition: border-color 0.3s, color 0.3s;
}
.ov-close:hover { border-color: var(--accent); color: var(--card-ink); }

.spoiler-gate { text-align: center; padding: 0.6rem 0.2rem; }
.spoiler-gate h2 { margin-bottom: 1.4rem; }
.spoiler-gate p { max-width: 30em; margin-left: auto; margin-right: auto; }

.wt-stepline {
  font-variant: small-caps; letter-spacing: 0.22em; font-size: 0.72rem;
  color: var(--hint-ink); margin-bottom: 0.5rem;
}
.wt-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1.8rem; gap: 0.6rem;
}
.wt-nav .btn { margin-top: 0; white-space: nowrap; }
.wt-dots { display: flex; gap: 0.45rem; flex-wrap: wrap; justify-content: center; }
.wt-dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  border: 1px solid var(--hint-ink); background: transparent; cursor: pointer; padding: 0;
  transition: background 0.25s, border-color 0.25s;
}
.wt-dot.on, .wt-dot:hover { background: var(--accent); border-color: var(--accent); }

.wt-live {
  border-left: 2px solid var(--gold);
  padding: 0.5rem 0 0.5rem 0.9rem;
  margin: 1rem 0;
  font-size: 0.92rem;
  color: var(--card-ink-soft);
  line-height: 1.65;
}
.wt-live-tag {
  display: block;
  font-variant: small-caps; letter-spacing: 0.18em; font-size: 0.7rem;
  color: var(--gold); margin-bottom: 0.2rem;
}

.yeargrid {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px;
  margin: 1.1rem 0 0.4rem;
}
.yearcell {
  border: 1px solid var(--card-edge); border-radius: 3px;
  padding: 0.35rem 0.15rem 0.3rem; text-align: center;
  min-width: 0;
}
.yearcell.now { box-shadow: 0 0 0 2px var(--accent); }
.yc-num { font-size: 0.72rem; color: var(--card-ink-soft); font-variant-numeric: tabular-nums; }
.tradetrack {
  height: 3px; background: color-mix(in srgb, var(--card-edge) 40%, transparent);
  border-radius: 2px; margin: 0.3rem 0.2rem;
  overflow: hidden;
}
.tradebar { height: 100%; background: var(--gold); }
.yc-marks { font-size: 0.6rem; line-height: 1.3; min-height: 0.9em; letter-spacing: 0.05em; }
.yc-sun { color: var(--card-ink-soft); margin-right: 0.15em; }
.yc-raid { color: #a04a32; word-break: break-all; }
.yc-legend {
  font-size: 0.78rem; font-style: italic; color: var(--hint-ink);
  margin-bottom: 1rem;
}

@media (max-width: 560px) {
  .yeargrid { grid-template-columns: repeat(5, 1fr); }
  .wt-nav { flex-wrap: wrap; }
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  #app { padding-top: 8.6rem; }
  .card { padding: 1.6rem 1.3rem 1.5rem; }
  #status { gap: 0.7rem; font-size: 0.82rem; top: 3rem; padding: 0.35rem 0.8rem; }
  #topbar .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition-duration: 0.2s !important; }
}
