:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #1c1915;
  --panel-soft: #231f19;
  --line: #392020;
  --text: #f0dfc3;
  --muted: #c7ad85;
  --accent: #833232;
  --accent-hot: #a4443f;
  --good: #98d67b;
  --bad: #d97777;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
}

button,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: grid;
  gap: 10px;
  padding: 18px clamp(16px, 3vw, 40px) 14px;
  background: #0f0f0e;
  border-bottom: 1px solid #2a221b;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.game-logo {
  display: block;
  width: min(360px, 72vw);
  max-height: 150px;
  object-fit: contain;
}

.version {
  color: var(--muted);
  font-size: 14px;
}

.status {
  min-height: 28px;
  padding: 8px 12px;
  background: var(--panel-soft);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.layout {
  display: grid;
  grid-template-columns: minmax(190px, 260px) 1fr minmax(210px, 300px);
  gap: 14px;
  padding: 14px clamp(12px, 2vw, 28px);
  min-height: 0;
}

.side-panel,
.story-panel {
  border: 1px solid #2d221b;
  background: var(--panel);
  min-width: 0;
}

.side-panel {
  padding: 14px;
  overflow: auto;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 18px;
}

.sheet,
.plot {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Courier New", monospace;
  font-size: 13px;
  line-height: 1.35;
}

.story-panel {
  display: flex;
  flex-direction: column;
  min-height: 58vh;
}

.story {
  flex: 1;
  overflow: auto;
  padding: clamp(22px, 4vw, 64px);
  text-align: center;
  font-size: clamp(18px, 1.4vw, 24px);
  line-height: 1.65;
  white-space: pre-wrap;
}

.story hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 30px auto;
  max-width: 460px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px clamp(12px, 2vw, 28px) 22px;
  background: #0f0f0e;
}

.choice {
  min-height: 54px;
  border: 0;
  background: var(--accent);
  color: #fff7ec;
  font-weight: 700;
  cursor: pointer;
  padding: 10px 12px;
}

.choice:hover,
.choice:focus-visible {
  background: var(--accent-hot);
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lang-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid #4d3c2a;
  padding: 6px 10px;
  background: var(--panel);
}

.lang-link:hover {
  border-color: var(--muted);
}

.utility-button {
  color: var(--text);
  border: 1px solid #4d3c2a;
  padding: 6px 10px;
  background: var(--panel);
  cursor: pointer;
}

.utility-button:hover,
.utility-button:focus-visible {
  border-color: var(--muted);
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.music-button.is-muted {
  color: #9f8766;
}

.music-volume-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid #4d3c2a;
  padding: 5px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

.music-volume-control input {
  width: 120px;
  accent-color: var(--accent-hot);
}

.music-volume-control input:focus-visible {
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.music-volume-control input:disabled {
  opacity: 0.45;
}

.notice {
  justify-self: center;
  max-width: min(620px, 100%);
  border: 1px solid #4d3c2a;
  padding: 7px 12px;
  background: #172015;
  color: var(--good);
  text-align: center;
}

.notice[hidden] {
  display: none;
}

.leaderboard-view {
  text-align: center;
}

.leaderboard-columns {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  text-align: left;
}

.leaderboard-columns section {
  border: 1px solid #4d3c2a;
  background: rgba(23, 20, 16, 0.62);
  padding: 18px;
}

.leaderboard-columns h3 {
  margin: 0 0 14px;
  color: var(--accent);
  text-align: center;
}

.leaderboard-warning {
  max-width: 760px;
  margin: 0 auto 28px;
  color: #d7b16d;
  font-size: 24px;
  line-height: 1.4;
}

.leaderboard-view pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  min-width: 132px;
  color: var(--text);
  border: 1px solid #4d3c2a;
  padding: 6px 10px;
  background: var(--panel-soft);
  cursor: pointer;
  list-style: none;
  overflow-wrap: anywhere;
  text-align: center;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-menu summary::after {
  content: " v";
  color: var(--muted);
}

.account-menu summary:hover,
.account-menu summary:focus-visible {
  border-color: var(--muted);
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.account-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 180px;
  border: 1px solid #4d3c2a;
  background: var(--panel);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.42);
}

.account-language-group {
  border-bottom: 1px solid #2d221b;
  padding: 10px 12px 12px;
}

.account-language-group p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.account-language-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.account-language-link {
  min-height: 34px;
  border: 1px solid #4d3c2a;
  padding: 7px 9px;
  color: var(--text);
  text-align: center;
  text-decoration: none;
}

.account-language-link:hover,
.account-language-link:focus-visible {
  border-color: var(--muted);
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.account-menu-panel button {
  min-height: 38px;
  border: 0;
  border-bottom: 1px solid #2d221b;
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.account-menu-panel button:last-child {
  border-bottom: 0;
}

.account-menu-panel button:hover,
.account-menu-panel button:focus-visible {
  background: var(--panel-soft);
  outline: 2px solid #d7b16d;
  outline-offset: -2px;
}

.account-menu-panel button:disabled {
  color: #7d6b55;
  cursor: not-allowed;
}

.mobile-info-menu,
.mobile-achievements-panel,
.mobile-panel-close {
  display: none;
}

.mobile-info-menu {
  position: relative;
}

.mobile-info-menu summary {
  color: var(--text);
  border: 1px solid #4d3c2a;
  padding: 6px 10px;
  background: var(--panel);
  cursor: pointer;
  list-style: none;
  text-align: center;
}

.mobile-info-menu summary::-webkit-details-marker {
  display: none;
}

.mobile-info-menu summary::after {
  content: " v";
  color: var(--muted);
}

.mobile-info-menu summary:hover,
.mobile-info-menu summary:focus-visible {
  border-color: var(--muted);
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.mobile-info-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 190px;
  border: 1px solid #4d3c2a;
  background: var(--panel);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.42);
}

.mobile-info-menu-panel button,
.mobile-panel-close {
  min-height: 38px;
  border: 0;
  border-bottom: 1px solid #2d221b;
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.mobile-info-menu-panel button:hover,
.mobile-info-menu-panel button:focus-visible,
.mobile-panel-close:hover,
.mobile-panel-close:focus-visible {
  background: var(--panel-soft);
  outline: 2px solid #d7b16d;
  outline-offset: -2px;
}

.progress {
  width: 100%;
  height: 8px;
  border: 1px solid #3f3327;
  background: #111;
  margin: 4px 0 10px;
}

.progress-fill {
  height: 100%;
  background: var(--good);
}

.game-over-image {
  display: block;
  max-width: min(760px, 100%);
  margin: 24px auto 0;
  border: 1px solid #4d3c2a;
}

.boss-reveal {
  margin: 0 auto;
  max-width: min(520px, 100%);
}

.boss-reveal img {
  display: block;
  width: 100%;
  border: 1px solid #4d3c2a;
  background: #080706;
}

.boss-reveal figcaption {
  margin-top: 10px;
  color: #d7b16d;
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.embedded-log,
.faq-panel {
  margin: 0 clamp(12px, 2vw, 28px) 14px;
  max-height: min(420px, 48vh);
  display: flex;
  flex-direction: column;
  border: 1px solid #4d3c2a;
  background: var(--panel);
}

.embedded-log[hidden],
.faq-panel[hidden] {
  display: none;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel-soft);
  border-bottom: 1px solid #2d221b;
}

.log-header h2 {
  margin: 0;
  font-size: 20px;
}

.log-content {
  overflow: auto;
  padding: clamp(18px, 3vw, 36px);
  white-space: pre-wrap;
  font-size: 18px;
  line-height: 1.55;
  text-align: left;
}

.log-content hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 22px 0;
}

.faq-content {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: clamp(16px, 2.5vw, 28px);
}

.faq-entry {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.faq-entry:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.faq-entry h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.faq-entry p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.faq-entry a {
  color: #e3c37e;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 4, 3, 0.72);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  border: 1px solid #6d5437;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-size: clamp(24px, 3vw, 34px);
}

.modal-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
  white-space: pre-line;
}

.modal-input {
  width: 100%;
  min-height: 48px;
  margin: 0 0 16px;
  border: 1px solid #6d5437;
  background: #11110f;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.modal-input[hidden] {
  display: none;
}

.modal-input:focus {
  outline: 2px solid #d7b16d;
  outline-offset: 2px;
}

.modal-helper,
.modal-error {
  margin: -8px 0 14px;
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
}

.modal-helper {
  color: var(--muted);
}

.modal-helper[hidden],
.modal-error[hidden] {
  display: none;
}

.modal-error {
  color: var(--bad);
}

.modal-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.choice-secondary {
  background: #4d3c2a;
}

.choice-secondary:hover,
.choice-secondary:focus-visible {
  background: #6d5437;
}

@media (max-width: 980px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    gap: 6px;
    padding: 8px 10px;
  }

  .title-row {
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .game-logo {
    width: min(120px, 32vw);
    max-height: 48px;
  }

  .version {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 12px;
  }

  .meta-row {
    display: grid;
    grid-template-columns: minmax(92px, 1fr) minmax(84px, auto) minmax(72px, 110px) auto auto;
    align-items: stretch;
    gap: 6px;
    overflow: visible;
  }

  .music-volume-control {
    min-height: 40px;
    min-width: 0;
    justify-content: center;
    padding: 5px 6px;
  }

  .music-volume-control span {
    display: none;
  }

  .music-volume-control input {
    width: min(100%, 96px);
  }

  .account-menu {
    min-width: 0;
  }

  .account-menu summary {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 8px;
    font-size: clamp(14px, 3.6vw, 16px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .utility-button,
  .mobile-info-menu summary {
    min-height: 40px;
    padding: 8px;
    font-size: clamp(14px, 3.6vw, 16px);
    white-space: nowrap;
  }

  .account-menu[open] summary {
    border-color: var(--muted);
  }

  .mobile-info-menu {
    display: block;
  }

  .account-menu-panel {
    position: fixed;
    top: 104px;
    right: 8px;
    left: 8px;
    z-index: 70;
    max-height: min(62svh, 420px);
    min-width: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .account-language-link {
    display: grid;
    min-height: 40px;
    place-items: center;
  }

  .account-menu-panel button {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 16px;
  }

  .account-menu-panel button:disabled {
    display: none;
  }

  .mobile-info-menu-panel {
    position: fixed;
    top: 92px;
    right: 10px;
    width: min(210px, calc(100vw - 20px));
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .story-panel {
    order: 1;
    min-height: 54svh;
  }

  .player-panel,
  .plot-panel,
  .mobile-achievements-panel {
    position: fixed;
    top: 132px;
    right: 10px;
    left: 10px;
    z-index: 50;
    display: none;
    max-height: min(58svh, 520px);
    padding: 12px;
    overflow: auto;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55);
  }

  .side-panel.is-open {
    display: block;
  }

  body.mobile-panel-open .story-panel {
    filter: brightness(0.72);
  }

  .mobile-panel-close {
    display: block;
    float: right;
    min-height: 34px;
    margin: -2px 0 10px 12px;
    border: 1px solid #4d3c2a;
    padding: 6px 10px;
    background: var(--panel);
  }

  .choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: sticky;
    bottom: 0;
    z-index: 6;
  }

  .leaderboard-columns {
    grid-template-columns: 1fr;
  }

  .modal-choices {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .topbar {
    padding-inline: 8px;
  }

  .meta-row {
    grid-template-columns: minmax(84px, 1fr) minmax(78px, auto) minmax(58px, 76px) auto auto;
    gap: 5px;
  }

  .music-volume-control input {
    width: 64px;
  }

  .account-menu summary,
  .utility-button,
  .mobile-info-menu summary {
    padding-inline: 6px;
  }

  .choices {
    grid-template-columns: 1fr;
  }

  .story {
    padding: 20px 16px;
  }
}
