/* =====================================================
   NINJA LIFE: ink and paper
   =====================================================
   Dark ink around the edges, warm paper for your story and the
   popups, and a red seal stamp for the big buttons.
   Only fonts that come with Windows are used, so it works offline. */

/* ---------- Colours and fonts ---------- */

:root {
  color-scheme: dark; /* dark scrollbars to match the theme */
  --ink: #131418;          /* page background */
  --ink-raised: #1b1d23;   /* dark cards */
  --ink-hover: #242730;
  --ink-line: #2d3039;
  --ink-text: #ece4d2;
  --ink-muted: #9a9384;
  --paper: #f2e9d6;        /* the story scroll and popups */
  --paper-light: #f8f2e4;
  --paper-shade: #e8dcc2;
  --paper-line: #d3c4a2;
  --sumi: #2a2521;         /* ink on paper */
  --sumi-muted: #776b5d;
  --seal: #c0412b;         /* red seal stamp: the accent */
  --seal-hover: #cf4a33;
  --gold: #c79d43;
  --good: #3d7a44;
  --bad: #ab3527;
  --font-display: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --font-body: "Segoe UI", system-ui, sans-serif;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #23252d 0%, transparent 70%),
    var(--ink);
  color: var(--ink-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

button {
  font: inherit;
  cursor: pointer;
}

/* Touch screens: no grey flash on tap, and no zoom on a quick double tap */
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
label {
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

.icon-sprite {
  position: absolute;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

/* "dvh" leaves out the browser's own toolbars (Safari on iPhone and iPad);
   older browsers use the "vh" line instead */
.screen {
  height: 100vh;
  height: 100dvh;
}

/* ---------- Brush stroke behind a title ---------- */

.brush {
  position: relative;
  z-index: 0;
  display: inline-block;
}

.brush::before {
  content: "";
  position: absolute;
  left: -10px;
  right: -14px;
  bottom: 0.05em;
  z-index: -1;
  height: 0.55em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 24' preserveAspectRatio='none'%3E%3Cpath d='M3 15 C 30 7, 90 5, 150 6 C 175 6, 192 8, 198 11 C 196 14, 186 15, 170 15 C 120 15, 60 17, 8 21 C 2 21, 0 18, 3 15 Z' fill='%23c0412b'/%3E%3Ccircle cx='192' cy='17' r='1.6' fill='%23c0412b'/%3E%3Ccircle cx='185' cy='19' r='1' fill='%23c0412b'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
  opacity: 0.85;
}

/* ---------- The red seal button (Age up, Begin life) ---------- */

.seal-button {
  border: 0;
  border-radius: var(--radius);
  background: var(--seal);
  color: var(--paper);
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  box-shadow:
    inset 0 0 0 3px var(--seal),
    inset 0 0 0 4px rgba(255, 255, 255, 0.35),
    0 6px 18px rgba(192, 65, 43, 0.25);
  transition: transform 0.15s ease, background 0.15s ease;
}

@media (hover: hover) {
  .seal-button:hover {
    background: var(--seal-hover);
    transform: translateY(-1px);
  }
}

.seal-button:active {
  transform: translateY(1px) scale(0.99);
}

/* =====================================================
   START SCREEN
   ===================================================== */

.start {
  overflow-y: auto;
  /* keep clear of the notch and the rounded corners */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  text-align: center;
}

#start-form {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
}

.start h1 {
  margin: 40px 0 0;
  font-family: var(--font-display);
  font-size: clamp(44px, 8vw, 72px);
  font-weight: normal;
  letter-spacing: 0.04em;
  color: var(--paper);
}

.tagline {
  margin: 6px 0 34px;
  font-family: var(--font-display);
  font-size: 18px;
  font-style: italic;
  color: var(--ink-muted);
}

/* The name box, and the test start menu from test-start.js */
.name-field,
#start-form > label,
#start-form > select {
  display: block;
  width: 100%;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

.name-field label,
#start-form > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

#start-form input[type=text],
#start-form select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--ink-line);
  border-radius: 8px;
  background: var(--ink-raised);
  color: var(--ink-text);
  font: inherit;
  font-size: 16px; /* smaller text makes iPhones zoom in when you tap the field */
}

#start-form input[type=text]:focus,
#start-form select:focus {
  outline: 2px solid var(--seal);
  outline-offset: 1px;
}

#start-form > label {
  margin-top: 30px;
}

.pick-title {
  margin: 34px 0 6px;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: normal;
}

.group-title {
  margin: 18px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--seal);
}

.group-blurb {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--ink-muted);
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  text-align: left;
}

.pick-grid.clans {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  margin-top: 12px;
}

.pick-card {
  display: block;
  cursor: pointer;
}

/* The real radio button is hidden; the card shows the selection. */
.pick-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.card-body {
  display: grid;
  grid-template-columns: 1fr;
  align-content: center;
  gap: 2px 14px;
  height: 100%;
  padding: 12px 14px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card-body.with-art {
  grid-template-columns: 52px 1fr;
}

.card-body .art {
  grid-row: 1 / 5;
  width: 52px;
  height: 52px;
}

.card-body strong {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: normal;
}

.card-body strong em {
  margin-left: 4px;
  font-size: 13px;
  font-style: normal;
  color: var(--ink-muted);
}

.card-body small {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-muted);
}

.card-body small.bonus {
  font-size: 12px;
  color: var(--gold);
}

@media (hover: hover) {
  .pick-card:hover .card-body {
    border-color: #4a4e5b;
    transform: translateY(-2px);
  }
}

.pick-card input:checked + .card-body {
  border-color: var(--seal);
  box-shadow: 0 0 0 1px var(--seal);
}

.pick-card input:focus-visible + .card-body {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}

/* "Begin life" stays in view at the bottom while you scroll */
.begin {
  position: sticky;
  bottom: calc(18px + env(safe-area-inset-bottom));
  margin: 34px 0 40px;
  padding: 14px 54px;
  font-size: 22px;
}

/* =====================================================
   GAME SCREEN
   ===================================================== */

.game {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr); /* both columns fill the window height */
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  /* at least 20px, more where a notch or the home bar needs room */
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #3a3d47 transparent;
}

.card {
  flex: none;
  padding: 16px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
}

.card-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: normal;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* ---------- Profile ---------- */

.profile {
  text-align: center;
}

/* The drawn face of your character (see face.js), in a ring of your clan colour */
.portrait {
  width: 116px;
  height: 116px;
  margin: 2px auto 10px;
  overflow: hidden;
  border-radius: 50%;
  background: #2a2d36;
  box-shadow: 0 0 0 3px var(--clan, #5d6470), 0 0 0 5px var(--paper-line);
}

.portrait svg {
  display: block;
  width: 100%;
  height: 100%;
}

.portrait.dead {
  filter: grayscale(1);
  opacity: 0.6;
}

.name {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: normal;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.rank {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.renown-box {
  margin: 12px 0 8px;
  text-align: left;
}

.renown-box .track {
  height: 6px;
}

.renown-box small {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-muted);
}

.origin {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.clan-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--clan, #5d6470);
  box-shadow: 0 0 0 1px var(--paper-line);
}

.fame {
  display: inline-block;
  margin-top: 10px;
  padding: 2px 10px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  font-size: 12px;
  color: var(--gold);
}

/* A rogue's bounty, in place of the fame chip (rogue.js) */
.fame.bounty {
  border-color: var(--seal);
  background: rgba(192, 65, 43, 0.12);
  color: #e0806b;
  font-variant-numeric: tabular-nums;
}

/* The title people gave you as Meijin (ranks.js) */
.earned-title {
  margin: 3px 0 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-style: italic;
  color: var(--paper-shade);
}

/* ---------- Honours: techniques, gear, squad (ranks.js) ---------- */

.honours-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.honour {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 4px;
}

.honour .icon {
  margin-top: 2px;
  color: var(--gold);
}

.honour span {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.honour b {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: normal;
}

.honour small {
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-muted);
}

/* A Toryo's painted portrait: in colour, in a gold frame */
.painted-portrait {
  display: inline-block;
  flex: none;
  padding: 5px;
  border-radius: 3px;
  background: linear-gradient(135deg, #e6c56e, #9c7426 45%, #dcb65c 70%, #87631e);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.painted-portrait .portrait {
  width: 76px;
  height: 94px;
  margin: 0;
  border-radius: 2px;
  background: #3d3427;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
}

/* ---------- Bars ---------- */

.track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #2a2d35;
}

.track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--fill, var(--gold));
  transition: width 0.6s ease;
}

/* ---------- Stats ---------- */

.stat {
  display: grid;
  grid-template-columns: 22px 1fr 30px;
  align-items: center;
  gap: 4px 10px;
  padding: 5px 4px;
  border-radius: 6px;
}

.stat .icon {
  width: 20px;
  height: 20px;
  color: var(--fill);
}

.stat .label {
  font-size: 13px;
}

.stat .value {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink-muted);
}

.stat .track {
  grid-column: 2 / 4;
  height: 6px;
}

/* A stat that just changed glows for a moment */
.stat.flash-up {
  animation: flash-up 1.2s ease;
}

.stat.flash-down {
  animation: flash-down 1.2s ease;
}

@keyframes flash-up {
  0%, 40% { background: rgba(90, 170, 100, 0.22); }
  100% { background: transparent; }
}

@keyframes flash-down {
  0%, 40% { background: rgba(200, 70, 50, 0.25); }
  100% { background: transparent; }
}

/* ---------- People ---------- */

.people-group {
  margin: 12px 0 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--seal);
}

.people-group:first-child {
  margin-top: 0;
}

.person {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
}

@media (hover: hover) {
  .person:hover:not(:disabled) {
    background: var(--ink-hover);
  }
}

.person .who {
  min-width: 0;
  font-size: 14px;
}

.person .who small {
  margin-left: 4px;
  color: var(--ink-muted);
}

.person .track {
  grid-column: 1 / 3;
  height: 4px;
}

.person .track span {
  background: #c98a8a;
}

.people-empty {
  margin: 0;
  font-size: 13px;
  color: var(--ink-muted);
}

/* Three dots: what you can still do with this person this year */
.pips {
  display: flex;
  align-items: center;
  gap: 3px;
}

.pips i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
}

.pips i.used {
  background: transparent;
  box-shadow: inset 0 0 0 1px #5a5648;
}

/* ---------- Story ---------- */

.story {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.story-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 6px 12px;
}

.age-block {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.age-num {
  font-family: var(--font-display);
  font-size: 54px;
  line-height: 1;
  color: var(--paper);
}

.age-block small {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.head-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--ink-line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 13px;
}

.icon-button .icon {
  width: 16px;
  height: 16px;
}

@media (hover: hover) {
  .icon-button:hover {
    border-color: #444855;
    color: var(--ink-text);
  }
}

@media (hover: hover) {
  #abandon-button:hover {
    border-color: var(--bad);
    color: #e08a7e;
  }
}

/* The life story: a paper scroll */
.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 34px 28px;
  border-radius: 4px;
  background:
    linear-gradient(90deg, rgba(120, 90, 50, 0.1), transparent 4%, transparent 96%, rgba(120, 90, 50, 0.1)),
    var(--paper);
  color: var(--sumi);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 0 0 1px var(--paper-line);
  scrollbar-color: var(--paper-line) transparent;
}

/* "Age 27": one divider per year */
.year {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 4px;
  font-family: var(--font-display);
  font-size: 19px;
}

.year::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--paper-line);
}

.seal-mark {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 4px;
  border-radius: 7px;
  background: var(--seal);
  color: var(--paper);
  font-size: 13px;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.entry {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
}

.entry + .entry {
  border-top: 1px dashed var(--paper-line);
}

.entry-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--sumi-muted);
  border-radius: 50%;
  color: var(--sumi);
}

.entry-icon .icon {
  width: 16px;
  height: 16px;
}

.entry-kind {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sumi-muted);
}

.entry-text {
  margin: 1px 0 0;
  font-family: var(--font-display);
  font-size: 16.5px;
  line-height: 1.55;
}

.entry.promotion .entry-icon {
  border-color: var(--gold);
  background: var(--gold);
  color: #fff;
}

.entry.promotion .entry-text {
  font-weight: bold;
}

.entry.bad .entry-icon {
  border-color: var(--bad);
  color: var(--bad);
}

.entry.death .entry-icon {
  border-color: var(--sumi);
  background: var(--sumi);
  color: var(--paper);
}

.entry.death .entry-text {
  font-weight: bold;
}

/* New lines are inked onto the scroll */
.new {
  animation: ink-in 0.7s ease both;
}

@keyframes ink-in {
  from { opacity: 0; transform: translateY(6px); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  padding: 1px 8px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 12px;
}

.chip.up {
  background: rgba(61, 122, 68, 0.13);
  color: var(--good);
}

.chip.down {
  background: rgba(171, 53, 39, 0.12);
  color: var(--bad);
}

.chip.renown {
  background: rgba(199, 157, 67, 0.2);
  color: #8a6420;
}

/* ---------- Action bar ---------- */

.actions {
  display: flex;
  gap: 10px;
  padding-top: 14px;
}

.action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 10px 8px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--ink-text);
}

.action .icon {
  width: 20px;
  height: 20px;
  color: var(--gold);
}

.action small {
  font-size: 11px;
  color: var(--ink-muted);
  white-space: nowrap;
}

@media (hover: hover) {
  .action:hover:not(:disabled) {
    border-color: var(--gold);
  }
}

.action:disabled {
  opacity: 0.45;
}

.action.seal-button {
  flex: 1.6;
  justify-content: center;
  border: 0;
  background: var(--seal);
  color: var(--paper);
  font-size: 20px;
}

.action.seal-button small {
  font-family: var(--font-body);
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.75);
}

/* =====================================================
   POPUP: a hanging scroll
   ===================================================== */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding:
    max(30px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(30px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(8, 9, 12, 0.72);
  backdrop-filter: blur(3px);
}

.choice-box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(480px, 100%);
  max-height: calc(100vh - 60px);
  max-height: calc(100dvh - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  background: var(--paper);
  color: var(--sumi);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: unroll 0.35s ease both;
}

/* The wooden rods at the top and bottom */
.choice-box::before,
.choice-box::after {
  content: "";
  position: absolute;
  left: -14px;
  right: -14px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(180deg, #6b4a2e, #3e2a19 60%, #2c1d11);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.choice-box::before {
  top: -10px;
}

.choice-box::after {
  bottom: -10px;
}

@keyframes unroll {
  from { clip-path: inset(0 0 100% 0); }
  to { clip-path: inset(-20px -20px -20px -20px); }
}

.choice-body {
  overflow-y: auto; /* long lists (like People) scroll inside the popup */
  padding: 26px 26px 22px;
  scrollbar-color: var(--paper-line) transparent;
}

#choice-title,
#hall-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: normal;
}

#choice-title .brush::before,
#hall-title .brush::before {
  opacity: 0.35;
}

/* pre-line: long texts (like a student's sheet) can use several lines */
#choice-text {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 16px;
  white-space: pre-line;
}

.choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Group titles inside a popup (Family, Friends, ...) */
.choice-heading {
  margin: 10px 0 -2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--seal);
}

.choice-options button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 10px;
  padding: 10px 14px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper-light);
  color: var(--sumi);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.choice-options button b {
  font-size: 15px;
  font-weight: 600;
}

.choice-options button small {
  grid-column: 1;
  font-size: 13px;
  color: var(--sumi-muted);
}

/* "64% chance" sits on the right of the button */
.choice-options button .chance {
  grid-row: 1 / 3;
  grid-column: 2;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--paper-shade);
  font-size: 12px;
  white-space: nowrap;
}

.choice-options button:focus-visible {
  border-color: var(--seal);
  outline: none;
  transform: translateX(3px);
  box-shadow: -3px 0 0 var(--seal);
}

@media (hover: hover) {
  .choice-options button:not(:disabled):hover {
    border-color: var(--seal);
    transform: translateX(3px);
    box-shadow: -3px 0 0 var(--seal);
  }
}

.choice-options button:disabled {
  opacity: 0.45;
}

/* Close / Back / Keep playing: the quiet way out */
.choice-options button.quiet {
  background: transparent;
  border-style: dashed;
}

/* =====================================================
   LEGACY SCROLL AND HALL OF LIVES (see legacy.js)
   ===================================================== */

.hall-overlay {
  z-index: 20;
}

.legacy-overlay {
  z-index: 30; /* opens on top of the hall */
}

.choice-box.legacy {
  width: min(640px, 100%);
}

.choice-box.hall {
  width: min(560px, 100%);
}

/* On the start screen, under the tagline */
.hall-button {
  margin: -18px auto 22px;
}

/* Buttons at the bottom of a scroll */
.scroll-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.scroll-buttons .seal-button {
  padding: 8px 26px;
  font-size: 17px;
}

.quiet-button {
  padding: 8px 16px;
  border: 1px dashed var(--paper-line);
  border-radius: 8px;
  background: transparent;
  color: var(--sumi);
}

@media (hover: hover) {
  .quiet-button:hover {
    border-color: var(--sumi-muted);
  }
}

.quiet-button.danger {
  border-style: solid;
  border-color: var(--bad);
  color: var(--bad);
}

/* ---------- The legacy scroll ---------- */

.legacy-head {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}

.legacy-head .portrait {
  width: 96px;
  height: 96px;
  margin: 0;
  box-shadow: 0 0 0 3px var(--sumi-muted), 0 0 0 5px var(--paper-line);
}

.here-lies {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sumi-muted);
}

#legacy-name {
  margin: 2px 0;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: normal;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#legacy-name .brush::before {
  opacity: 0.35;
}

.legacy-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 19px;
  font-style: italic;
  color: var(--seal);
}

.legacy-meta {
  margin: 0;
  font-size: 13px;
  color: var(--sumi-muted);
}

.legacy-nature {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 16px;
}

.trait-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait {
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--paper-shade);
  font-size: 12px;
  text-transform: capitalize;
}

/* Section titles with a thin line after them */
.legacy-body h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--seal);
}

.legacy-body h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--paper-line);
}

.remembered {
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-display);
  font-size: 16px;
}

.remembered li {
  position: relative;
  padding: 4px 0 4px 20px;
}

/* a small red diamond instead of a bullet */
.remembered li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.9em;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--seal);
  transform: rotate(45deg);
}

.funeral {
  margin: 0 0 10px;
  padding: 8px 14px;
  border-left: 3px solid var(--paper-line);
  border-radius: 0 8px 8px 0;
  background: var(--paper-light);
}

.funeral p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-style: italic;
}

.funeral cite {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-style: normal;
  color: var(--sumi-muted);
}

.highlights {
  margin: 0;
  padding: 0;
  list-style: none;
}

.highlights li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  font-family: var(--font-display);
  font-size: 15.5px;
}

.highlights .seal-mark {
  flex: none;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.number {
  padding: 8px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper-light);
  text-align: center;
}

.number b {
  display: block;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: normal;
}

.number small {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sumi-muted);
}

/* ---------- The hall of lives ---------- */

.hall-text {
  margin: 0 0 12px;
  font-family: var(--font-display);
}

.hall-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hall-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper-light);
  color: var(--sumi);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

@media (hover: hover) {
  .hall-row:hover {
    border-color: var(--seal);
    transform: translateX(3px);
  }
}

.hall-row .portrait {
  width: 44px;
  height: 44px;
  margin: 0;
  box-shadow: 0 0 0 2px var(--paper-line);
}

.hall-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hall-who b {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: normal;
}

.hall-who em {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--seal);
}

.hall-who small {
  font-size: 12px;
  color: var(--sumi-muted);
}

/* The Hall of Toryo: every Toryo you have been, in a row of frames */
.toryo-gallery {
  margin-bottom: 14px;
  padding: 12px 14px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: rgba(199, 157, 67, 0.1);
}

.gallery-title {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sumi-muted);
}

.gallery-row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 2px 6px;
}

.gallery-frame {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  width: 92px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--sumi);
}

.gallery-frame .painted-portrait {
  margin-bottom: 6px;
  transition: transform 0.15s ease;
}

@media (hover: hover) {
  .gallery-frame:hover .painted-portrait {
    transform: translateY(-3px);
  }
}

.gallery-frame .portrait {
  width: 60px;
  height: 74px;
}

.gallery-frame b {
  max-width: 100%;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-frame small {
  font-size: 11px;
  color: var(--sumi-muted);
}

/* On the legacy scroll of a Toryo */
.toryo-painting {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper-light);
}

.toryo-painting figcaption {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--sumi-muted);
}

.hall-confirm {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(171, 53, 39, 0.08);
}

.hall-confirm p {
  margin: 0 0 8px;
}

.hall-confirm button + button {
  margin-left: 8px;
}

/* =====================================================
   PHONE TOP BAR AND PROFILE SHEET (shown on phones only, see below)
   ===================================================== */

.mini,
.sheet-close {
  display: none;
}

.mini-bar {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 12px 8px 8px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--ink-text);
  text-align: left;
}

.mini-bar .portrait {
  width: 46px;
  height: 46px;
  margin: 0;
  box-shadow: 0 0 0 2px var(--clan, #5d6470), 0 0 0 3px var(--paper-line);
}

.mini-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mini-who b,
.mini-who small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-who b {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: normal;
  line-height: 1.25;
}

.mini-who small {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.mini-fame {
  color: var(--ink-muted);
}

.mini-bounty {
  color: #e0806b;
}

.mini-more {
  font-size: 26px;
  line-height: 1;
  color: var(--ink-muted);
}

/* All six stats in a small strip under the top bar */
.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 12px;
  padding: 6px 4px 2px;
}

.mini-stats .stat {
  grid-template-columns: 15px minmax(0, 1fr) auto;
  gap: 1px 6px;
  padding: 3px 2px;
}

.mini-stats .stat .icon {
  width: 15px;
  height: 15px;
}

.mini-stats .stat .label,
.mini-stats .stat .value {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-stats .stat .track {
  height: 4px;
}

.sheet-close {
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: none;
  min-height: 48px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--ink-text);
  font-family: var(--font-display);
  font-size: 17px;
}

.sheet-close::before {
  content: "‹";
  font-size: 24px;
  line-height: 1;
  color: var(--ink-muted);
}

/* =====================================================
   TOUCH SCREENS (phones, tablets)
   ===================================================== */

@media (hover: none) {
  /* A short press shows where you tapped (hover effects are off) */
  .action:not(:disabled):active,
  .person:not(:disabled):active,
  .mini-bar:active,
  .sheet-close:active,
  .icon-button:active {
    background: var(--ink-hover);
  }

  .choice-options button:not(:disabled):active {
    border-color: var(--seal);
    box-shadow: -3px 0 0 var(--seal);
  }

  .hall-row:active {
    border-color: var(--seal);
  }

  /* No keyboard to press Space on */
  #age-button small {
    display: none;
  }
}

/* =====================================================
   TABLETS (iPad in portrait) AND NARROW WINDOWS:
   two columns, with a slimmer left one
   ===================================================== */

@media (max-width: 1060px) {
  .game {
    grid-template-columns: 268px minmax(0, 1fr);
    gap: 14px;
    padding:
      max(14px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
  }

  .card {
    padding: 14px;
  }

  .profile .portrait {
    width: 100px;
    height: 100px;
  }

  .log {
    padding: 6px 26px 24px;
  }
}

/* Wide but short: a phone on its side */
@media (min-width: 701px) and (max-height: 520px) {
  .game {
    gap: 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .story-head {
    padding-bottom: 6px;
  }

  .age-num {
    font-size: 32px;
  }

  .actions {
    padding-top: 8px;
  }

  .action {
    padding: 7px 6px;
  }

  .action small {
    display: none;
  }
}

/* =====================================================
   PHONES (iPhone upright): the story fills the screen
   ===================================================== */
/* A slim top bar and stat strip sit above the story, the buttons below.
   Tap the top bar to see everything else (profile, honours, people)
   in a sheet over the story. */

@media (max-width: 700px) {
  .screen.game {
    display: flex;
    flex-direction: column;
    padding:
      calc(env(safe-area-inset-top) + 8px)
      max(12px, env(safe-area-inset-right))
      0
      max(12px, env(safe-area-inset-left));
  }

  .story {
    flex: 1;
  }

  .mini {
    display: block;
    margin-bottom: 6px;
  }

  /* The left column, as a sheet over the story */
  .side {
    display: none;
  }

  .game.sheet-open .side {
    position: fixed;
    inset: 0;
    z-index: 8; /* under the popups, so choices still show on top */
    display: flex;
    padding:
      calc(env(safe-area-inset-top) + 10px)
      max(14px, env(safe-area-inset-right))
      calc(env(safe-area-inset-bottom) + 24px)
      max(14px, env(safe-area-inset-left));
    background: var(--ink);
    overscroll-behavior: contain;
  }

  .sheet-close {
    display: flex;
  }

  .profile {
    display: grid;
    grid-template-columns: 84px 1fr;
    align-items: center;
    gap: 0 14px;
    text-align: left;
  }

  .profile .portrait {
    grid-row: 1 / 8;
    width: 80px;
    height: 80px;
    margin: 0;
  }

  .fame {
    justify-self: start;
  }

  .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
  }

  .honours-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
  }

  /* The age and the two small buttons share one slim row */
  .story-head {
    align-items: center;
    padding: 2px 2px 8px;
  }

  .age-num {
    font-size: 30px;
  }

  .head-buttons .icon-button {
    min-width: 40px;
    min-height: 36px;
    justify-content: center;
    font-size: 0; /* icons only; the words are still read out by screen readers */
  }

  .head-buttons .icon-button .icon {
    width: 18px;
    height: 18px;
  }

  .log {
    padding: 4px 16px 20px;
  }

  .year {
    margin-top: 20px;
  }

  .actions {
    gap: 8px;
    padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  }

  .action {
    justify-content: center;
    min-height: 56px;
    padding: 8px 4px;
  }

  .action small {
    display: none;
  }

  .action.seal-button {
    font-size: 19px;
  }
}

/* Less movement for people who ask their system for it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
