:root {
  --ink: #14101f;
  --panel: #1f1830;
  --line: #3a2f55;
  --text: #efe7d6;
  --muted: #b9b0cf;
  --gold: #f6cf48;
  --gold-dark: #b8862a;
  --red: #85253a;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --body: 'VT323', ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body { font-family: var(--body); font-size: 22px; }

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 3px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name {
  font-family: var(--pixel);
  font-size: 12px;
  color: var(--gold);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--ink);
  background: var(--gold);
  padding: 4px 6px;
}
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--panel);
  color: var(--text);
  border: 3px solid var(--line);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .icon-off { display: none; }
.icon-btn.is-muted .icon-on { display: none; }
.icon-btn.is-muted .icon-off { display: block; }
.icon-btn:focus-visible, .btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- stage ---------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d0a16;
  outline: 3px solid var(--line);
}

/* ---------- menu screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(20, 16, 31, 0.97);
  padding: 20px 16px calc(24px + var(--safe-b));
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.screen.is-hidden { display: none; }
.panel {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  margin: auto 0;
}
.kicker { margin: 0; font-family: var(--pixel); font-size: 10px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.title {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(18px, 6vw, 26px);
  line-height: 1.3;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--red);
}
.art-row { display: flex; align-items: flex-end; justify-content: center; gap: 12px; padding: 4px 0; }
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.art { margin: 2px auto; }
.art.is-dim { filter: grayscale(1) brightness(0.6); }
.story { margin: 0; font-size: 22px; line-height: 1.1; color: var(--text); }
.captive { margin: 0; font-size: 22px; line-height: 1.1; color: var(--gold); }
.sub { margin: 0; font-size: 22px; line-height: 1.1; }
.quote { margin: 0; font-size: 21px; line-height: 1.1; color: var(--muted); }
.help { margin: 0; font-size: 19px; color: var(--muted); }
.note { margin: 0; font-size: 18px; color: var(--muted); }
.note:empty, .shared:empty { display: none; }

/* Week meter: seven lanterns, Monday to Sunday, brighter as the week gets harder. */
.week { display: flex; justify-content: center; gap: 8px; }
.wk { display: flex; flex-direction: column; align-items: center; gap: 5px; font-family: var(--pixel); font-size: 9px; color: var(--muted); }
.wk::before { content: ""; width: 10px; height: 12px; background: var(--gold); opacity: calc(0.12 + var(--glow) * 0.4); }
.wk.is-today { color: var(--gold); }
.wk.is-today::before { opacity: 1; box-shadow: 0 0 0 2px var(--ink), 0 0 10px var(--gold); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn {
  font-family: var(--pixel);
  font-size: 13px;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--gold);
  border: 3px solid var(--ink);
  box-shadow: 0 5px 0 var(--gold-dark), 0 5px 0 3px var(--ink);
  padding: 16px 22px;
  min-height: 52px;
  width: 100%;
  max-width: 320px;
  cursor: pointer;
  transition: transform 0.05s;
  line-height: 1.4;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-dark), 0 1px 0 3px var(--ink); }
.btn-ghost { background: var(--panel); color: var(--text); box-shadow: 0 5px 0 var(--line), 0 5px 0 3px var(--ink); }
.btn-ghost:active { box-shadow: 0 1px 0 var(--line), 0 1px 0 3px var(--ink); }

.home { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 6px; }
.home p { margin: 0; font-size: 19px; color: var(--muted); }
.home-bar { height: 12px; background: var(--panel); border: 3px solid var(--line); }
.home-bar span { display: block; height: 100%; width: 0; background: #6cb24a; }

.stats {
  margin: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.stats div { background: var(--panel); border: 3px solid var(--line); padding: 8px 4px; }
.stats dt { font-family: var(--pixel); font-size: 8px; color: var(--muted); text-transform: uppercase; }
.stats dd { margin: 6px 0 0; font-size: 26px; color: var(--text); }

.share-text {
  margin: 0;
  width: 100%;
  max-width: 320px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--body);
  font-size: 20px;
  line-height: 1.15;
  background: #0d0a16;
  border: 3px dashed var(--line);
  padding: 10px 12px;
  -webkit-user-select: text;
  user-select: text;
}
.shared { margin: -4px 0 0; color: #6cb24a; font-size: 20px; }
.next { margin: 0; font-size: 20px; color: var(--muted); }
.next span { font-family: var(--pixel); font-size: 12px; color: var(--text); }

/* ---------- story ---------- */
.story-art { width: 100%; max-width: 420px; height: auto; aspect-ratio: 160 / 96; outline: 3px solid var(--line); cursor: pointer; }
.story-text { margin: 0; min-height: 3.4em; font-size: 24px; line-height: 1.1; color: var(--text); max-width: 420px; }
.story-dots { display: flex; gap: 8px; }
.story-dots span { width: 10px; height: 10px; background: var(--line); }
.story-dots span.on { background: var(--gold); }
.link-btn { background: none; border: 0; color: var(--muted); font-family: var(--body); font-size: 20px; text-decoration: underline; cursor: pointer; padding: 6px 10px; min-height: 44px; }
.link-btn[hidden] { display: none; }
.link-btn:focus-visible { outline: 3px solid var(--gold); }

/* ---------- loot line on the result screen ---------- */
.loot { margin: 0; font-size: 21px; color: var(--gold); }
.loot:empty { display: none; }

/* ---------- Hollowbrook ---------- */
.panel-village { max-width: 480px; gap: 12px; }
.village-map {
  width: 100%;
  height: auto;
  aspect-ratio: 240 / 176;
  outline: 3px solid var(--line);
  background: #72b84c;
  touch-action: manipulation;
  cursor: pointer;
}
.mats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.mat {
  font-size: 24px;
  background: var(--panel);
  border: 3px solid var(--line);
  padding: 4px 12px;
  min-width: 72px;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.v-msg { margin: 0; min-height: 44px; font-size: 20px; line-height: 1.1; color: var(--text); }
.v-actions { display: flex; gap: 8px; width: 100%; justify-content: center; }
.v-actions[hidden] { display: none; }
.btn-small { font-size: 10px; padding: 10px 8px; min-height: 44px; max-width: 140px; }
.catalog {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
}
.card {
  display: grid;
  grid-template-rows: 40px auto auto;
  justify-items: center;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  min-height: 108px;
  background: var(--panel);
  color: var(--text);
  border: 3px solid var(--line);
  font-family: var(--body);
  cursor: pointer;
}
.card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.card-art { height: 40px; width: auto; max-width: 48px; object-fit: contain; }
.card-name { font-family: var(--pixel); font-size: 8px; line-height: 1.4; text-transform: uppercase; }
.card-label { font-size: 19px; color: var(--muted); }
.card.is-buy .card-label, .card.is-stored .card-label { color: var(--gold); }
.card.is-stored { border-color: var(--gold-dark); }
.card.is-active { border-color: var(--gold); background: #2c2244; }
.card.is-poor { opacity: 0.75; }
.card.is-poor .card-label { color: #e08a8a; }
.card.is-locked, .card.is-done { opacity: 0.5; }
.card.is-locked .card-art { filter: grayscale(1) brightness(0.6); }

/* ---------- packing screen and workshop ---------- */
.v-head { margin: 8px 0 0; font-family: var(--pixel); font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }
.v-note { margin: -6px 0 0; font-size: 19px; color: var(--muted); }
.pick-card { grid-template-rows: 36px auto auto auto; min-height: 0; padding: 8px 6px; text-align: center; }
.pick-card .card-art, .pick-card .card-none { height: 36px; }
#p-go { position: sticky; bottom: calc(10px + var(--safe-b)); z-index: 2; box-shadow: 0 5px 0 var(--gold-dark), 0 5px 0 3px var(--ink), 0 -14px 24px 10px rgba(20, 16, 31, 0.96); }
.card-desc { font-size: 18px; line-height: 1; color: var(--text); }
.card-none { display: grid; place-items: center; font-size: 30px; color: var(--muted); height: 40px; }
.pepper-card { width: 100%; grid-template-columns: 56px 1fr; grid-template-rows: auto auto; justify-items: start; text-align: left; min-height: 0; column-gap: 10px; }
.pepper-card .card-art { grid-row: 1 / 3; align-self: center; height: 48px; max-width: 56px; }
.pepper-card.is-active { border-color: var(--gold); background: #2c2244; }
.card.is-active .card-label { color: var(--gold); }

/* On a phone held upright, keep the game near the top and the thumb space below. */
.touch body.is-playing #stage { align-items: flex-start; padding-top: 10px; }

/* ---------- touch controls ---------- */
#controls { display: none; }
.touch body.is-playing #controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px calc(14px + var(--safe-b));
  touch-action: none;
}
.pad {
  position: relative;
  width: 148px; height: 148px;
  border-radius: 50%;
  background: var(--panel);
  border: 4px solid var(--line);
  touch-action: none;
}
.pad.is-active { border-color: #6c5f92; }
.pad-arrow { position: absolute; width: 0; height: 0; border: 9px solid transparent; opacity: 0.7; }
.pad-up { top: 10px; left: 50%; margin-left: -9px; border-bottom-color: var(--muted); border-top-width: 0; }
.pad-down { bottom: 10px; left: 50%; margin-left: -9px; border-top-color: var(--muted); border-bottom-width: 0; }
.pad-left { left: 10px; top: 50%; margin-top: -9px; border-right-color: var(--muted); border-left-width: 0; }
.pad-right { right: 10px; top: 50%; margin-top: -9px; border-left-color: var(--muted); border-right-width: 0; }
.pad-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: var(--line);
  border: 3px solid #6c5f92;
  pointer-events: none;
}
.sword-btn {
  width: 104px; height: 104px;
  border-radius: 50%;
  background: var(--red);
  border: 4px solid #c93a3a;
  box-shadow: 0 6px 0 #4e1424;
  display: grid; place-items: center;
  touch-action: none;
  cursor: pointer;
}
.sword-btn svg { width: 50px; height: 50px; }
.sword-btn.is-active { transform: translateY(4px); box-shadow: 0 2px 0 #4e1424; }

/* Phone held sideways: the game fills the height and the controls sit
   in the empty space on either side of it. */
@media (orientation: landscape) and (max-height: 560px) {
  .touch body.is-playing .topbar { display: none; }
  .touch body.is-playing #stage { align-items: center; padding-top: 0; }
  .touch body.is-playing #controls {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    padding: 0 max(18px, env(safe-area-inset-left, 0px)) calc(18px + var(--safe-b)) max(18px, env(safe-area-inset-right, 0px));
    pointer-events: none;
  }
  .touch body.is-playing #controls .pad,
  .touch body.is-playing #controls .sword-btn { pointer-events: auto; }
  .touch body.is-playing #controls .pad { width: 132px; height: 132px; }
  .touch body.is-playing #controls .sword-btn { width: 92px; height: 92px; }
  .screen { padding-top: 12px; }
  .panel { gap: 10px; }
}

@media (min-width: 700px) {
  .brand-name { font-size: 14px; }
}
#v-talk { max-width: 260px; }

/* ---------- sign-in ---------- */
.a-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.a-form[hidden] { display: none; }
.a-label { align-self: flex-start; font-family: var(--pixel); font-size: 10px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.a-input {
  width: 100%; min-height: 52px; padding: 10px 14px;
  font-family: var(--body); font-size: 24px; color: var(--text);
  background: var(--ink); border: 3px solid var(--line); border-radius: 0;
}
.a-input:focus { outline: none; border-color: var(--gold); }
.a-code { font-family: var(--pixel); font-size: 20px; letter-spacing: 8px; text-align: center; }
.a-msg { margin: 0; font-size: 20px; color: var(--gold); min-height: 1em; }
.a-msg:empty { display: none; }
