/* ————————————————————————————————————————————————
   Japan Through Time — woodblock-print interface
   Palette: washi paper, sumi ink, beni red, ai indigo.
   ———————————————————————————————————————————————— */

@font-face {
  font-family: "Shippori Mincho";
  src: url("assets/fonts/shippori-mincho-v23-japanese_latin-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Shippori Mincho";
  src: url("assets/fonts/shippori-mincho-v23-japanese_latin-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #e9dfc7;
  --paper-hi: #f4edd9;
  --paper-lo: #d8cba9;
  --paper-deep: #c9b990;
  --sumi: #2b2521;
  --sumi-60: rgba(43, 37, 33, 0.6);
  --sumi-35: rgba(43, 37, 33, 0.35);
  --beni: #a63a2a;
  --beni-bright: #bc4530;
  --ai: #33506a;
  --sea: #d6dccc;
  --serif-jp: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--serif-jp);
  color: var(--sumi);
  background: var(--paper-lo);
  overflow: hidden;
}

/* the print sheet — washi grain via inline-SVG noise layered over paper tones */
#stage {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.55' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.32 0 0 0 0 0.27 0 0 0 0 0.18 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23p)'/%3E%3C/svg%3E"),
    radial-gradient(120% 90% at 30% 20%, var(--paper-hi) 0%, var(--paper) 55%, var(--paper-lo) 100%);
}
/* fibrous long-strand washi streaks — z-index lifts it over the map so the
   paper grain unifies land, sea and chrome into one printed sheet */
#stage::before {
  content: "";
  position: absolute; inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.16' numOctaves='2' seed='11'/%3E%3CfeColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.36 0 0 0 0 0.24 0 0 0 0.035 0'/%3E%3C/filter%3E%3Crect width='420' height='420' filter='url(%23f)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
/* vignette like an old print's toned edges */
#stage::after {
  content: "";
  position: absolute; inset: 0;
  z-index: 4;
  pointer-events: none;
  box-shadow: inset 0 0 130px rgba(105, 84, 50, 0.28);
}

/* ————— title block ————— */
#titleblock {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 64px;          /* fixed: text length varies between JA/EN, banner must not */
  flex: none;
  padding: 0 22px;
}
.cartouche {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid var(--sumi);
  outline: 1px solid var(--sumi-35);
  outline-offset: 3px;
  background: linear-gradient(160deg, var(--paper-hi), var(--paper));
  padding: 6px 14px;
}
.cartouche h1 {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.cartouche .jp { font-size: 24px; }
.cartouche .en {
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sumi-60);
}
.hanko {
  width: 26px; height: 26px;
  background: var(--beni);
  color: var(--paper-hi);
  font-size: 15px;
  line-height: 26px;
  text-align: center;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(166, 58, 42, 0.35);
  transform: rotate(-3deg);
}
.subtitle {
  font-size: 12.5px;
  color: var(--sumi-60);
  letter-spacing: 0.04em;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cartouche { flex: none; white-space: nowrap; }
.subtitle button {
  font: inherit;
  font-family: inherit;
  color: var(--beni);
  background: none;
  border: none;
  border-bottom: 1px solid rgba(166, 58, 42, 0.4);
  cursor: pointer;
  padding: 0 1px;
}
.subtitle button:hover { color: var(--beni-bright); }

#langBtn {
  margin-left: auto;
  align-self: center;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 4px 12px;
  border: 1.6px solid var(--sumi);
  background: var(--paper-hi);
  color: var(--sumi);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(43, 37, 33, 0.22);
}
#langBtn:hover { background: var(--paper); }

/* back-to-full-map pill, shown while a clan is highlighted */
#clearHl {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 7px 18px;
  border: 1.8px solid var(--sumi);
  border-radius: 999px;
  background: var(--beni);
  color: var(--paper-hi);
  cursor: pointer;
  box-shadow: 2px 3px 0 rgba(43, 37, 33, 0.3);
}
#clearHl:hover { background: var(--beni-bright); }

/* campaign arrows + battle markers */
#map .campaign-arrow {
  fill: none;
  stroke: #7e2f23;
  stroke-width: 1.7;
  stroke-dasharray: 5 2.6;
  stroke-linecap: round;
  opacity: 0.85;
}
#map .overlay-text {
  font-family: var(--serif-jp);
  font-size: 8.5px;
  font-weight: 700;
  fill: #7e2f23;
  text-anchor: middle;
  paint-order: stroke fill;
  stroke: rgba(244, 237, 217, 0.85);
  stroke-width: 2.4px;
  stroke-linejoin: round;
}
#map .marker-text { font-size: 7.5px; }
#map .unifier-text { font-size: 7.5px; fill: #4a3c30; }
#map .battle-marker, #map .unifier-marker { pointer-events: none; }

/* the three unifiers lifespan band — Gantt-style: each name rides on the same
   line as its bar, just past the death end. Staggered by death-year (x) and row
   (y) so they never collide; a JS guard flips any name that nears the right edge. */
#unifiers {
  position: relative;
  height: 34px;
  margin: 1px 0 1px 48px;
}
.uni-bar {
  position: absolute;
  height: 6px;
  border-radius: 3px;
  opacity: 0.9;
  box-shadow: inset 0 0 0 1px rgba(43, 37, 33, 0.25);
}
.uni-name {
  position: absolute;
  left: 100%;
  margin-left: 7px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9.5px;
  line-height: 1;
  white-space: nowrap;
  color: var(--sumi);
  letter-spacing: 0.02em;
}
.uni-name.flip {            /* name would overflow right edge → ride over the bar's right end */
  left: auto;
  right: 14px;
  margin-left: 0;
  text-shadow: 0 0 3px var(--paper-hi), 0 0 3px var(--paper-hi), 0 0 3px var(--paper-hi);
}
.uni-death {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translate(50%, -50%);
  font-size: 9px;
  color: var(--beni);
  font-weight: 700;
}

/* suggestions modal */
.suggest-card textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1.5px solid var(--sumi);
  background: var(--paper-hi);
  color: var(--sumi);
  resize: vertical;
  margin: 10px 0 12px;
}
.suggest-send {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  padding: 8px 22px;
  border: 1.8px solid var(--sumi);
  background: var(--beni);
  color: var(--paper-hi);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(43, 37, 33, 0.25);
}
.suggest-send:hover { background: var(--beni-bright); }
.suggest-direct {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--sumi-60);
}
.suggest-direct a { color: var(--ai); }

/* ————— map ————— */
#mapwrap {
  position: relative;
  flex: 1;
  min-height: 0;
}
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* interactive surface: dragging the map must never select text.
   Modals and the commentary panel stay selectable for copying. */
#stage { user-select: none; -webkit-user-select: none; }
.about-card, #insight { user-select: text; -webkit-user-select: text; }

#map .province {
  stroke: rgba(43, 37, 33, 0.5);
  stroke-width: 0.45;
  stroke-linejoin: round;
  transition: fill 0.7s ease, fill-opacity 0.7s ease;
  cursor: pointer;
}
#map .province:hover { stroke-width: 1.1; stroke: var(--sumi); }
#map .province.dimmed { fill-opacity: 0.25; }
#map .coast {
  fill: none;
  stroke: var(--sumi);
  stroke-width: 1.05;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: 0.82;
  pointer-events: none;
}
#map .lake {
  stroke: rgba(43, 37, 33, 0.45);
  stroke-width: 0.4;
  pointer-events: none;
}
#map .hatch-overlay { pointer-events: none; }

#map .clan-label { pointer-events: none; }
#map .clan-label text {
  font-family: var(--serif-jp);
  font-weight: 700;
  fill: var(--sumi);
  paint-order: stroke fill;
  stroke: rgba(244, 237, 217, 0.75);
  stroke-width: 2px;
  stroke-linejoin: round;
  text-anchor: middle;
}
#map .clan-label .label-kanji {
  font-weight: 500;
  fill: rgba(43, 37, 33, 0.78);
}

/* era stamp — vertical kanji floating in the Sea of Japan */
#eraStamp {
  position: absolute;
  top: 6%;
  left: 4%;
  pointer-events: none;
  text-align: center;
  opacity: 0.9;
}
#eraStamp .era-kanji {
  writing-mode: vertical-rl;
  font-size: clamp(34px, 5.2vh, 56px);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgba(43, 37, 33, 0.72);
  margin: 0 auto;
}
#eraStamp .era-year {
  margin-top: 10px;
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--beni);
  font-weight: 700;
}

/* in-depth commentary — to the right of the era stamp in the Sea of Japan;
   left/top are set dynamically in applySnapshot from the stamp's real size */
#insight {
  position: absolute;
  top: 6%;
  left: calc(4% + 110px);
  width: min(560px, 42vw);
  max-height: 60%;
  overflow-y: auto;
  padding: 12px 16px;
  background: linear-gradient(165deg, rgba(244, 237, 217, 0.82), rgba(233, 223, 199, 0.82));
  border: 1.5px solid var(--sumi-35);
  box-shadow: 2px 3px 0 rgba(43, 37, 33, 0.12);
  font-size: 12px;
  line-height: 1.65;
  z-index: 3;
  column-count: 2;
  column-gap: 20px;
}
#insight .ins-year {
  column-span: all;
  font-weight: 700;
  color: var(--beni);
  letter-spacing: 0.05em;
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--sumi-35);
}
#insight p { margin-bottom: 7px; }
#insight p:last-child { margin-bottom: 0; }
#insight cite {
  display: block;
  font-style: normal;
  font-size: 10.5px;
  color: var(--sumi-60);
  margin-top: 5px;
}

/* zoom controls */
#zoomCtl {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
}
#zoomCtl button {
  width: 30px;
  height: 30px;
  font-family: inherit;
  font-size: 15px;
  border: 1.6px solid var(--sumi);
  background: var(--paper-hi);
  color: var(--sumi);
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(43, 37, 33, 0.2);
}
#zoomCtl button:hover { background: var(--paper); }

#map .province, #map .coast { vector-effect: non-scaling-stroke; }

/* legend — bottom-right Pacific corner */
#legend {
  position: absolute;
  right: 14px;
  bottom: 10px;
  max-width: 300px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: flex-end;
  font-size: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px 2px 4px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 3px;
}
.legend-item:hover, .legend-item.active {
  border-color: var(--sumi-35);
  background: rgba(244, 237, 217, 0.6);
}
.legend-item .swatch {
  width: 11px; height: 11px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(43, 37, 33, 0.35);
}
.legend-item svg { width: 16px; height: 16px; }
.legend-item .nm { letter-spacing: 0.03em; }

/* tooltip */
#tooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  max-width: 260px;
  background: linear-gradient(165deg, var(--paper-hi), var(--paper));
  border: 1.5px solid var(--sumi);
  box-shadow: 3px 4px 0 rgba(43, 37, 33, 0.25);
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.45;
}
#tooltip .tt-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}
#tooltip .tt-head svg { width: 26px; height: 26px; flex: none; }
#tooltip .tt-prov { font-weight: 700; font-size: 14px; }
#tooltip .tt-prov .k { color: var(--sumi-60); font-weight: 500; margin-left: 6px; }
#tooltip .tt-clan { color: var(--beni); font-weight: 700; }
#tooltip .tt-blurb { color: var(--sumi-60); margin-top: 2px; }
#tooltip .tt-contested {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px dashed var(--sumi-35);
  color: #7a4a22;
  font-style: italic;
}
#tooltip.pinned {
  border-left: 4px solid var(--beni);
  box-shadow: 4px 5px 0 rgba(43, 37, 33, 0.3);
}

/* ————— time bar ————— */
#timebar {
  position: relative;
  z-index: 5;
  padding: 2px 22px 14px;
}
#caption {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  height: 38px;            /* fixed: 2 lines of caption — never reflows the layout */
  margin-bottom: 4px;
  overflow: hidden;
}
#capYear {
  font-size: 19px;
  font-weight: 700;
  color: var(--beni);
  letter-spacing: 0.05em;
  line-height: 1.35;
  flex: none;
}
#capText {
  font-size: 13px;
  line-height: 1.35;
  color: var(--sumi);
  opacity: 0.85;
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;   /* show up to two lines, then ellipsis */
  line-clamp: 2;
  overflow: hidden;
}
#sliderRow {
  display: flex;
  align-items: center;
  gap: 14px;
}
#playBtn {
  font-family: inherit;
  width: 34px; height: 34px;
  flex: none;
  border: 1.8px solid var(--sumi);
  background: var(--paper-hi);
  color: var(--sumi);
  font-size: 14px;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: 2px 2px 0 rgba(43, 37, 33, 0.25);
}
#playBtn:hover { background: var(--paper); }
#playBtn.playing { background: var(--beni); color: var(--paper-hi); border-color: var(--beni); }

#slider {
  position: relative;
  flex: 1;
  height: 46px;
  cursor: pointer;
  touch-action: none;
}
#eraBands {
  position: absolute;
  left: 0; right: 0; top: 12px;
  height: 22px;
  display: flex;
  border: 1.5px solid var(--sumi);
  background: var(--paper-hi);
  overflow: hidden;
}
.era-band {
  position: relative;
  height: 100%;
  border-right: 1px solid var(--sumi-35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--sumi-60);
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
.era-band:last-child { border-right: none; }
.era-band .bk { font-size: 11.5px; margin-right: 4px; color: var(--sumi); }
#ticks { position: absolute; left: 0; right: 0; top: 34px; height: 6px; pointer-events: none; }
.tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 5px;
  background: var(--sumi-60);
}
#handle {
  position: absolute;
  top: 2px;
  width: 0;
  height: 42px;
  pointer-events: none;
  transition: left 0.18s ease;
}
.handle-knob {
  position: absolute;
  left: -7px;
  top: 0;
  width: 14px;
  height: 42px;
  background:
    linear-gradient(180deg, var(--beni) 0 8px, transparent 8px),
    linear-gradient(180deg, transparent 0 8px, rgba(43,37,33,0.0) 8px);
}
.handle-knob::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  width: 2px;
  height: 36px;
  background: var(--beni);
}

/* ————— modals (about / suggestions / legal share the overlay) ————— */
#aboutModal,
#suggestModal,
#legalModal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(43, 37, 33, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.about-card {
  position: relative;
  width: min(680px, 90vw);
  max-height: 82vh;
  overflow: auto;
  background: linear-gradient(165deg, var(--paper-hi), var(--paper));
  border: 2px solid var(--sumi);
  outline: 1px solid var(--sumi-35);
  outline-offset: 4px;
  padding: 26px 32px;
  font-size: 13.5px;
  line-height: 1.65;
}
.about-card h2 { font-size: 19px; margin-bottom: 10px; letter-spacing: 0.04em; }
.about-card h3 { font-size: 14px; margin: 16px 0 5px; color: var(--beni); letter-spacing: 0.06em; }
.about-card p { margin-bottom: 8px; }
.about-card ul { margin: 4px 0 8px 20px; }
.about-card a { color: var(--ai); }
.about-close {
  position: absolute;
  top: 8px; right: 12px;
  font-size: 22px;
  font-family: inherit;
  background: none;
  border: none;
  color: var(--sumi-60);
  cursor: pointer;
}
.about-close:hover { color: var(--sumi); }

[hidden] { display: none !important; }
