:root {
  --ink: #12110d;
  --field: #33302a; /* the field behind the plates: dark, so the drawing is the light */
  --field-ink: 242, 239, 228; /* ink that sits on the field rather than on a plate */
  --card: rgba(255, 255, 255, 0.82);
  --muted: #55524a; /* small caps labels: dark enough to hold on the card over the dark field */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: var(--field);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

#view {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --- header --------------------------------------------------------------- */
.bar {
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  pointer-events: none;
}

.mark {
  color: rgb(var(--field-ink));
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.sub {
  font-size: 8.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(var(--field-ink), 0.62);
}

.back {
  margin-left: auto;
  pointer-events: auto;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgb(var(--field-ink));
  text-decoration: none;
  border-bottom: 1px solid rgba(var(--field-ink), 0.4);
  padding-bottom: 1px;
}

.back:hover {
  border-color: rgb(var(--field-ink));
}

/* --- story arc ------------------------------------------------------------ */
.story {
  position: absolute;
  left: 50%;
  bottom: calc(190px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: min(520px, 78vw);
  padding: 8px 12px 9px;
  transform: translateX(-50%);
  border: 1px solid rgba(18, 17, 13, 0.45);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}

.story[hidden] {
  display: none;
}

.story.on {
  opacity: 1;
}

.story-act {
  font-size: 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.story-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink);
}

/* --- hud ------------------------------------------------------------------ */
.hud {
  position: absolute;
  left: 18px;
  bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 104px;
  padding: 8px 11px 7px;
  border: 1.4px solid rgba(18, 17, 13, 0.6);
  background: var(--card);
  backdrop-filter: blur(2px);
}

.k {
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.block strong {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.block em {
  font-size: 8px;
  font-style: normal;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.meter {
  display: none;
  width: 100%;
  height: 2px;
  margin-top: 2px;
  overflow: hidden;
  background: rgba(18, 17, 13, 0.14);
}

.meter.on {
  display: block;
}

.meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width 60ms linear;
}

/* --- the sealed door ------------------------------------------------------ */
.lock {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 10;
  width: min(88vw, 360px);
  padding: 14px 16px 13px;
  transform: translate(-50%, -50%);
  border: 1.5px solid var(--ink);
  background: var(--card);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
}

.lock[hidden] {
  display: none;
}

.lock-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 7px;
  margin-bottom: 11px;
  border-bottom: 1px solid rgba(18, 17, 13, 0.25);
}

.lock-count {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 14px;
}

.lock-dials {
  display: flex;
  gap: 8px;
}

.dial {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px 4px;
  border: 1px solid rgba(18, 17, 13, 0.35);
  background: rgba(255, 255, 255, 0.52);
}

.dial strong {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 27px;
  font-weight: 400;
  line-height: 1;
}

.dial em {
  font-size: 7.5px;
  font-style: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.dial button {
  width: 100%;
  padding: 1px 0;
  border: 0;
  border-top: 1px solid rgba(18, 17, 13, 0.18);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}

.dial button:last-child {
  border-top: 0;
  border-bottom: 1px solid rgba(18, 17, 13, 0.18);
}

.dial button:active {
  background: var(--ink);
  color: #f6f4ec;
}

.lock-msg {
  min-height: 1.3em;
  margin: 11px 0 10px;
  font-size: 9px;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.lock-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.lock-actions button {
  padding: 7px 15px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}

.lock-actions button:first-child {
  background: var(--ink);
  color: #f6f4ec;
}

.lock-actions button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* --- thumb pad ------------------------------------------------------------ */
.pad {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stick {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 1.5px solid rgba(var(--field-ink), 0.45);
  background: rgba(255, 255, 255, 0.06);
  pointer-events: auto;
  touch-action: none;
}

.stick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  border: 1.5px solid rgba(var(--field-ink), 0.9);
  background: rgba(var(--field-ink), 0.9);
  pointer-events: none;
}

.buttons {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.buttons button {
  pointer-events: auto;
  width: 68px;
  height: 68px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font: inherit;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
}

.buttons button.fire {
  background: var(--ink);
  color: #f6f4ec;
}

.buttons button.fire:active {
  background: #f6f4ec;
  color: var(--ink);
}

.buttons button.reload {
  border-color: rgba(var(--field-ink), 0.7);
}

/* --- foot ----------------------------------------------------------------- */
.foot {
  position: absolute;
  left: 168px;
  right: 168px;
  bottom: 22px;
  margin: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 9px;
  letter-spacing: 0.06em;
  color: rgba(var(--field-ink), 0.62);
  pointer-events: none;
}

/* --- touch log (temporary) ------------------------------------------------ */
.log {
  position: absolute;
  top: 54px;
  right: 12px;
  z-index: 8;
  width: min(56vw, 230px);
  padding: 5px 6px 6px;
  border: 1px solid rgba(18, 17, 13, 0.5);
  background: rgba(255, 255, 255, 0.86);
  font-size: 8.5px;
  line-height: 1.35;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.log[hidden] {
  display: none;
}

.log-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  justify-content: space-between;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 7.5px;
  border-bottom: 1px solid rgba(18, 17, 13, 0.25);
  padding-bottom: 3px;
  margin-bottom: 3px;
}

.log-head button {
  pointer-events: auto;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 11px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.log-body {
  max-height: 104px;
  overflow: hidden;
}

.log-row {
  padding: 1px 0;
  border-bottom: 1px dotted rgba(18, 17, 13, 0.16);
  word-break: break-word;
}

.log-row b {
  font-weight: 400;
  color: #7a3f10;
}

kbd {
  font: inherit;
  border: 1px solid rgba(var(--field-ink), 0.45);
  padding: 0 3px;
  margin-right: 1px;
}

@media (max-width: 760px) {
  .hud {
    bottom: auto;
    top: 54px;
    flex-direction: row;
  }
  .log {
    top: 112px;
    right: 12px;
    width: min(62vw, 214px);
  }
  .foot {
    display: none;
  }
  .story {
    top: 42%;
    bottom: auto;
    width: min(82vw, 340px);
    transform: translate(-50%, -50%);
  }
  .block {
    min-width: 0;
    padding: 6px 9px;
  }
  .block strong {
    font-size: 15px;
  }
  .hud {
    flex-wrap: wrap;
  }
  .lock {
    width: min(92vw, 330px);
  }
}
