: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; }

.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;
}
.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); }

/* 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; }
}
