:root {
  --bg: #0d0a1c;
  --panel: rgba(30, 23, 61, 0.9);
  --panel-soft: rgba(48, 36, 91, 0.72);
  --text: #f8f4ff;
  --muted: #c8bddc;
  --gold: #f1c96b;
  --gold-soft: #ffe8a5;
  --purple: #8268ff;
  --purple-soft: #bf77ff;
  --green: #84e7b4;
  --red: #ff9f9f;
  --blue: #88c8ff;
  --border: rgba(255,255,255,.12);
  --shadow: 0 24px 65px rgba(0,0,0,.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 8%, rgba(130,104,255,.24), transparent 30%),
    radial-gradient(circle at 90% 25%, rgba(191,119,255,.16), transparent 28%),
    linear-gradient(155deg, #0d0a1c, #17122f 56%, #090711);
  overflow-x: hidden;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.stars, .stars::before, .stars::after {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.52) 0 1px, transparent 1.4px),
    radial-gradient(circle, rgba(241,201,107,.34) 0 1px, transparent 1.5px);
  background-size: 125px 125px, 190px 190px;
  background-position: 18px 28px, 72px 110px;
  opacity: .31;
}
.stars::before { transform: translate(38px, 20px); opacity: .26; }
.stars::after { transform: translate(-25px, 48px); opacity: .18; }

.topbar, .app-shell, footer { position: relative; z-index: 1; }

.topbar {
  width: min(1160px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.brand-button {
  padding: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.brand-button small {
  display: block;
  color: var(--gold);
  font-size: .65rem;
  letter-spacing: .13em;
  font-weight: 900;
}
.brand-button strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(.95rem, 4vw, 1.25rem);
}
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241,201,107,.28);
  border-radius: 14px;
  color: var(--gold-soft);
  background: rgba(241,201,107,.08);
}

.header-actions { display: flex; align-items: center; gap: 9px; }

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  background: rgba(19,14,40,.75);
  cursor: pointer;
}

.wallet {
  min-width: 82px;
  padding: 10px 14px;
  display: flex;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(241,201,107,.27);
  border-radius: 999px;
  background: rgba(19,14,40,.76);
}

.app-shell {
  width: min(1160px, calc(100% - 28px));
  margin: 18px auto 34px;
}

.view { display: none; animation: fadeIn .28s ease; }
.view.active { display: block; }

.panel {
  border: 1px solid var(--border);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), transparent 22%),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(17px);
}

.hero-panel, .card-panel {
  max-width: 800px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 46px);
}

.hero-panel { text-align: center; }

h1, h2, h3, p { overflow-wrap: anywhere; }

.hero-panel h1, .card-panel h2, .view-heading h2, .modal h2 {
  margin: 13px 0 10px;
  font-size: clamp(1.75rem, 7.5vw, 3.35rem);
  line-height: 1.04;
  letter-spacing: -.045em;
}

p { color: var(--muted); line-height: 1.65; }

.kicker {
  color: var(--gold);
  font-size: .7rem;
  letter-spacing: .14em;
  font-weight: 900;
}

.crest {
  width: 88px;
  height: 88px;
  margin: 22px auto 6px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241,201,107,.3);
  border-radius: 50%;
  color: var(--gold-soft);
  font-size: 2rem;
  background: radial-gradient(circle, rgba(241,201,107,.2), transparent 68%);
  box-shadow: 0 0 42px rgba(241,201,107,.1);
}
.crest.small { width: 68px; height: 68px; font-size: 1.5rem; }

.rule-grid {
  margin: 28px 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.rule-card {
  padding: 18px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,.035);
}
.rule-card > span { font-size: 1.55rem; }
.rule-card strong { display: block; margin-top: 8px; }
.rule-card p { margin: 5px 0 0; font-size: .9rem; line-height: 1.45; }

.safety-note {
  margin: 20px 0;
  padding: 15px 17px;
  border-left: 3px solid var(--gold);
  border-radius: 13px;
  color: var(--gold-soft);
  background: rgba(241,201,107,.08);
  text-align: left;
}

.primary-button, .secondary-button, .choice-button, .help-button, .shop-button {
  border: 0;
  cursor: pointer;
}
.primary-button {
  width: 100%;
  min-height: 57px;
  margin-top: 12px;
  padding: 15px 20px;
  border-radius: 17px;
  color: #181124;
  font-weight: 950;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  box-shadow: 0 13px 30px rgba(241,201,107,.15);
}
.primary-button:disabled, .secondary-button:disabled, .help-button:disabled, .shop-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.secondary-button {
  min-height: 46px;
  padding: 11px 16px;
  border: 1px solid rgba(241,201,107,.28);
  border-radius: 14px;
  color: var(--gold-soft);
  font-weight: 800;
  background: rgba(241,201,107,.07);
}
.text-button {
  padding: 8px 3px;
  border: 0;
  color: var(--gold-soft);
  background: transparent;
  cursor: pointer;
}

.door-art { height: 210px; display: grid; place-items: center; }
.door-shape {
  width: 130px;
  height: 185px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(241,201,107,.62);
  border-bottom: 0;
  border-radius: 70px 70px 10px 10px;
  background: linear-gradient(180deg, rgba(130,104,255,.18), rgba(0,0,0,.25));
  box-shadow: 0 0 45px rgba(130,104,255,.22);
}
.door-shape span {
  width: 55px;
  height: 55px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241,201,107,.3);
  border-radius: 50%;
  color: var(--gold);
  font-size: 1.6rem;
  background: rgba(13,10,28,.7);
}

.puzzle-box {
  margin-top: 24px;
  padding: clamp(18px, 4vw, 27px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(7,5,17,.28);
}
.large-sequence {
  margin: 12px 0 22px;
  text-align: center;
  color: var(--gold-soft);
  font-size: clamp(1.55rem, 7vw, 2.3rem);
  letter-spacing: .12em;
}
.choice-grid { display: grid; gap: 11px; }
.choice-grid.three { grid-template-columns: repeat(3, 1fr); }
.choice-button {
  min-height: 57px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-weight: 850;
  background: var(--panel-soft);
}
.choice-button:hover { border-color: rgba(241,201,107,.45); }

.feedback { min-height: 23px; margin: 13px 0 0; font-weight: 800; }
.feedback.success { color: var(--green); }
.feedback.error { color: var(--red); }

.view-heading {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.view-heading h2 { margin-bottom: 6px; }
.view-heading p { max-width: 720px; margin: 0; }

.branch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.branch-card {
  min-height: 270px;
  padding: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 25px;
  color: var(--text);
  background:
    linear-gradient(145deg, rgba(255,255,255,.055), transparent 35%),
    rgba(31,24,63,.88);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.branch-card.locked { opacity: .7; }
.branch-card.complete { border-color: rgba(132,231,180,.42); }
.branch-icon { font-size: 2.1rem; }
.branch-card h3 { margin: 18px 0 6px; font-size: 1.55rem; }
.branch-card p { margin: 0 0 18px; }
.branch-meta {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: .86rem;
}
.status-pill {
  width: max-content;
  margin-top: 12px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--gold-soft);
  background: rgba(241,201,107,.06);
  font-size: .75rem;
  font-weight: 850;
}

.progress-panel {
  margin-top: 22px;
  padding: 19px 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 20px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: rgba(255,255,255,.035);
}
.progress-panel strong { display: block; margin-top: 4px; }
.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
}
.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--gold));
  transition: width .3s ease;
}

.stage-list { display: grid; gap: 22px; }
.stage-section {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255,255,255,.025);
}
.stage-heading {
  margin-bottom: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stage-heading h3 { margin: 0; font-size: 1.12rem; }
.stage-heading span { color: var(--muted); font-size: .8rem; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 13px;
}
.path-card {
  min-height: 180px;
  padding: 17px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  background: rgba(31,24,63,.82);
  cursor: pointer;
}
.path-card.locked { opacity: .48; cursor: not-allowed; }
.path-card.solved { border-color: rgba(132,231,180,.4); }
.path-card h4 { margin: 15px 0 7px; font-size: 1rem; }
.path-card p { margin: 0; font-size: .84rem; line-height: 1.45; }
.path-card .card-symbol { font-size: 1.4rem; }
.path-card .mini-status { margin-top: auto; padding-top: 14px; color: var(--gold-soft); font-size: .75rem; font-weight: 850; }

.card-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 13px;
}
.difficulty-badge, .reward-badge, .card-stage {
  display: inline-flex;
  width: max-content;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 900;
}
.difficulty-badge { color: #171125; background: var(--gold); text-transform: uppercase; }
.card-stage { margin-left: 6px; color: var(--muted); border: 1px solid var(--border); }
.reward-badge { color: var(--gold-soft); border: 1px solid rgba(241,201,107,.24); background: rgba(241,201,107,.06); }

.requirements {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}
.requirement {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.028);
}
.requirement.met { color: var(--green); }

.answer-input {
  width: 100%;
  min-height: 54px;
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  outline: none;
  background: rgba(7,5,17,.4);
}
.answer-input:focus {
  border-color: rgba(241,201,107,.5);
  box-shadow: 0 0 0 4px rgba(241,201,107,.07);
}
.puzzle-question { color: var(--text); font-size: 1.02rem; white-space: pre-line; }
.clue-list { display: grid; gap: 9px; margin: 16px 0; }
.clue-row {
  padding: 12px 13px;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255,255,255,.028);
}
.clue-row span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #171125;
  background: var(--gold);
  font-size: .72rem;
  font-weight: 900;
}

.sequence-output {
  min-height: 64px;
  margin: 15px 0;
  padding: 10px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  border: 1px dashed rgba(255,255,255,.25);
  border-radius: 14px;
}
.sequence-token {
  min-width: 47px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241,201,107,.35);
  border-radius: 11px;
  color: var(--gold-soft);
  background: rgba(241,201,107,.07);
  font-weight: 900;
}
.token-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 9px; }
.token-button {
  min-height: 55px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: var(--panel-soft);
  cursor: pointer;
  font-weight: 850;
}
.sequence-actions { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 9px; }

.help-area {
  margin-top: 18px;
  padding-top: 17px;
  border-top: 1px solid var(--border);
}
.help-area h3 { margin: 0 0 11px; font-size: 1rem; }
.help-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; }
.help-button {
  min-height: 63px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: rgba(255,255,255,.035);
}
.help-button strong, .help-button small { display: block; }
.help-button small { margin-top: 4px; color: var(--gold-soft); }
.purchased-help {
  margin-top: 10px;
  padding: 12px;
  border-left: 3px solid var(--purple-soft);
  border-radius: 11px;
  color: var(--text);
  background: rgba(191,119,255,.08);
}

.gate-panel { text-align: center; }
.gate-panel .requirements { text-align: left; }

.shop-wallet {
  min-width: 150px;
  padding: 13px 16px;
  border: 1px solid rgba(241,201,107,.28);
  border-radius: 16px;
  background: rgba(241,201,107,.07);
}
.shop-wallet span { display: block; color: var(--muted); font-size: .75rem; }
.shop-wallet strong { font-size: 1.5rem; color: var(--gold-soft); }

.lock-message { margin-bottom: 18px; padding: 18px; }
.shop-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.shop-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: rgba(31,24,63,.85);
}
.shop-card .shop-icon { font-size: 1.7rem; }
.shop-card h3 { margin: 12px 0 6px; }
.shop-card p { margin: 0; font-size: .85rem; }
.shop-price { margin: 14px 0 10px; color: var(--gold-soft); font-weight: 900; }
.shop-button {
  width: 100%;
  min-height: 45px;
  border-radius: 12px;
  color: #171125;
  font-weight: 900;
  background: var(--gold);
}
.claim-panel { margin-top: 18px; padding: 19px; }
.claim-panel h3 { margin-top: 0; }
.claim-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }

.modal {
  width: min(760px, calc(100% - 24px));
  max-height: 88vh;
  padding: clamp(20px,4vw,34px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  background: #17122f;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(5,3,12,.78); backdrop-filter: blur(5px); }
.modal-head { display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; }
.modal-head h2 { font-size: clamp(1.5rem,6vw,2.5rem); }
.journal-section { margin-top: 20px; }
.journal-section h3 { margin-bottom: 10px; }
.journal-entry {
  margin-bottom: 9px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.03);
}
.journal-entry strong { display: block; color: var(--gold-soft); }
.journal-entry span { display: block; margin-top: 4px; color: var(--muted); }
.inventory-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 9px; }
.inventory-item {
  padding: 12px;
  border: 1px solid rgba(132,231,180,.25);
  border-radius: 12px;
  background: rgba(132,231,180,.05);
}
.reward-modal { text-align: center; position: relative; overflow: hidden; }
.reward-glow {
  position: absolute;
  width: 260px;
  height: 260px;
  top: -130px;
  left: calc(50% - 130px);
  border-radius: 50%;
  background: rgba(241,201,107,.18);
  filter: blur(30px);
}

.answer-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: .86rem; }
.answer-table th, .answer-table td { padding: 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.parent-actions { display: grid; grid-template-columns: repeat(2,1fr); gap: 9px; margin: 16px 0; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 28px);
  padding: 12px 17px;
  transform: translate(-50%, 110px);
  opacity: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  background: #21183f;
  box-shadow: var(--shadow);
  transition: .25s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

footer {
  width: min(1160px, calc(100% - 28px));
  margin: 0 auto;
  padding: 0 0 26px;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  color: var(--muted);
  font-size: .84rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 800px) {
  .branch-grid, .shop-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: repeat(2,1fr); }
  .view-heading { flex-direction: column; }
  .shop-wallet { width: 100%; }
}

@media (max-width: 590px) {
  .rule-grid, .card-grid, .help-grid, .inventory-grid { grid-template-columns: 1fr; }
  .rule-card { text-align: left; }
  .choice-grid.three { grid-template-columns: 1fr; }
  .progress-panel { grid-template-columns: 1fr; }
  .token-grid { grid-template-columns: repeat(2,1fr); }
  .sequence-actions { grid-template-columns: 1fr 1fr; }
  .sequence-actions .primary-button { grid-column: 1 / -1; }
  .card-topline { align-items: flex-start; }
  .parent-actions { grid-template-columns: 1fr; }
  footer { flex-direction: column; align-items: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}


.map-actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

@media (max-width: 590px) {
  .map-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }
}


.install-button {
  min-height: 42px;
  padding: 9px 13px;
  border: 1px solid rgba(241,201,107,.34);
  border-radius: 13px;
  color: #181124;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  font-weight: 900;
  cursor: pointer;
}

.map-actions,
.backup-actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.backup-panel {
  margin: 16px 0 22px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255,255,255,.03);
}
.backup-panel p { margin: 7px 0 12px; }
.file-button { display: inline-grid; place-items: center; cursor: pointer; }

.update-banner {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: min(680px, calc(100% - 28px));
  padding: 13px 15px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(241,201,107,.35);
  border-radius: 16px;
  color: var(--text);
  background: #21183f;
  box-shadow: var(--shadow);
}
.update-banner[hidden] { display: none; }
.update-banner button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: 11px;
  color: #181124;
  background: var(--gold);
  font-weight: 900;
  cursor: pointer;
}

@media (max-width: 590px) {
  .map-actions,
  .backup-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .install-button { padding-inline: 10px; }
  .update-banner { align-items: stretch; flex-direction: column; }
}
