:root {
  color-scheme: dark;
  font-family: "Inter", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: #f0e7d7;
  background: #0d1019;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 280px;
  margin: 0;
  background: radial-gradient(ellipse at 72% 9%, #27213a 0%, #11141f 53%, #0d1019 85%);
  min-height: 100vh;
}

.game { width: min(100% - 48px, 1140px); margin: auto; padding: clamp(26px, 7.5vh, 82px) 0 48px; }
.masthead { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 23px; }
.brand { display: flex; align-items: center; gap: 13px; }
.header-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.55rem, 4vw, 2.9rem); line-height: 1.08; letter-spacing: -.095em; }

.brand-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 1px solid #b8895a;
  border-radius: 9px;
  background: linear-gradient(145deg, #48313b, #221e2b);
  box-shadow: inset 0 0 0 3px #23202b, 0 0 24px #d48b4e24;
}
.brand-icon::before {
  content: "";
  width: 23px;
  height: 25px;
  background: linear-gradient(150deg, #f4df93, #d8944c 66%, #9a5151);
  clip-path: polygon(53% 14%, 65% 14%, 65% 6%, 82% 6%, 82% 18%, 58% 26%, 58% 37%, 72% 30%, 89% 38%, 97% 54%, 95% 73%, 79% 93%, 61% 93%, 50% 87%, 38% 94%, 19% 92%, 7% 74%, 4% 52%, 13% 36%, 29% 30%, 47% 38%, 47% 20%);
}

.layout {
  --accent: #f6ae53;
  --accent-light: #fff1ad;
  display: grid;
  grid-template-columns: minmax(0, 2.24fr) minmax(250px, 1fr);
  gap: 16px;
}

.world, .forge {
  background: #171a27;
  border: 1px solid #4e4556;
  border-radius: 16px;
  box-shadow: 0 16px 50px #07091090;
  overflow: hidden;
}
.world { align-self: start; }

.scene {
  position: relative;
  background: #27233f;
}
#scene { display: block; width: 100%; height: auto; aspect-ratio: 384 / 220; image-rendering: pixelated; }
.scene::after {
  --line: #d6b7919e;
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  background:
    linear-gradient(var(--line), var(--line)) left top / 13px 1px,
    linear-gradient(var(--line), var(--line)) left top / 1px 13px,
    linear-gradient(var(--line), var(--line)) right top / 13px 1px,
    linear-gradient(var(--line), var(--line)) right top / 1px 13px,
    linear-gradient(var(--line), var(--line)) left bottom / 13px 1px,
    linear-gradient(var(--line), var(--line)) left bottom / 1px 13px,
    linear-gradient(var(--line), var(--line)) right bottom / 13px 1px,
    linear-gradient(var(--line), var(--line)) right bottom / 1px 13px;
  background-repeat: no-repeat;
}

.route-chip, #restart { position: absolute; top: 17px; }
.route-chip {
  left: 17px;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 37%, #322b3d);
  border-radius: 6px;
  background: #121620df;
  color: var(--accent-light);
  font-size: .76rem;
  line-height: 1.2;
}
#restart { right: 17px; }

.forge {
  display: flex;
  flex-direction: column;
  padding: clamp(17px, 2.4vw, 30px);
  background: linear-gradient(156deg, #262232, #1a1c2a 36%, #151826);
}
.forge-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #bfb5c3; font-size: .77rem; }
.record { white-space: nowrap; }
.record strong { margin-left: 4px; color: var(--accent-light); font-family: "IBM Plex Mono", Consolas, monospace; font-weight: 600; }
.apple-info { margin: auto 0; padding: 28px 0 22px; }
.level {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--accent);
  font: 700 clamp(1.55rem, 4vw, 2.6rem) / 1 "IBM Plex Mono", Consolas, monospace;
  text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 35%, transparent);
}
h2 { font-size: clamp(1.6rem, 3.3vw, 2.48rem); letter-spacing: -.087em; line-height: 1.18; word-break: keep-all; overflow-wrap: anywhere; }
.apple-info p { margin-top: 12px; min-height: 2.9em; font-size: .9rem; color: #c7bfca; line-height: 1.5; word-break: keep-all; }
.apple-info .result { margin-top: 8px; min-height: auto; color: var(--accent-light); font-weight: 700; }
.layout[data-result="failed"] .result, .layout[data-result="down"] .result { color: #ffb299; }
.layout[data-result="protected"] .result, .layout[data-result="eat"] .result { color: #aee8c8; }
.layout[data-result="great"] .result { color: #ffdb84; text-shadow: 0 0 15px #ffba5d75; }

.action { border-top: 1px solid #3d374a; padding-top: 17px; }
.odds { margin-bottom: 16px; }
.odds-labels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; color: #c5bdc8; font-size: .76rem; }
.odds-labels span { display: flex; justify-content: space-between; gap: 5px; }
.odds-labels strong { color: #f5edda; }
.odds-labels [data-odds="failed"] strong { color: #f29c9a; }
.odds-labels [data-odds="great"] strong { color: var(--accent-light); }
.odds-labels .unavailable { opacity: .55; }
.final-form { margin-bottom: 13px; color: var(--accent-light); font-size: .76rem; }
.expert { margin-bottom: 12px; padding: 8px 10px; border-radius: 6px; background: #282431; color: #d8cadd; font-size: .76rem; }
.layout[data-expert="true"] .expert { color: #ffe5a0; background: #51383c; box-shadow: inset 0 0 0 1px #e3a75b86, 0 0 19px #ffb65122; }
.layout[data-expert="true"] .world { border-color: #d99164; }

button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid #ffe5ae; outline-offset: 4px; }
button[aria-disabled="true"] { cursor: default; }
.quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #615063;
  border-radius: 7px;
  color: #e2d9dc;
  background: #1a1b29e8;
  white-space: nowrap;
  font-size: .76rem;
}
.quiet:hover { background: #312a3d; }
.quiet[aria-disabled="true"] { opacity: .55; }
.sound-icon { display: inline-block; width: 13px; height: 13px; background: #e5b477; clip-path: polygon(0 35%, 30% 35%, 68% 5%, 68% 95%, 30% 65%, 0 65%, 0 35%, 88% 35%, 100% 44%, 100% 56%, 88% 65%); }
[aria-pressed="false"] .sound-icon { background: #8d8191; }
#upgrade {
  width: 100%;
  min-height: 51px;
  border: 1px solid var(--accent-light);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--accent-light), var(--accent));
  color: #171525;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 54%, #11131b);
  font-weight: 800;
}
#upgrade:hover { filter: brightness(1.09); }
#upgrade:active { transform: translateY(2px); }
#upgrade[aria-disabled="true"] { filter: saturate(.64) brightness(.85); }
.eat-button { width: 100%; min-height: 38px; margin-top: 11px; }

.shop {
  margin-top: 16px;
  padding: clamp(16px, 2.3vw, 26px);
  border: 1px solid #4e4556;
  border-radius: 16px;
  background: #191b29;
  box-shadow: 0 16px 50px #07091062;
}
.shop-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 15px; }
.shop-heading h2 { font-size: 1.18rem; }
.shop-heading div { color: #cbbeca; font-size: .81rem; text-align: right; }
.shop-heading strong { display: inline-block; margin-left: 4px; color: #f6d986; font: 700 1.05rem "IBM Plex Mono", Consolas, monospace; }
.shop-heading small { display: block; margin-top: 4px; color: #dec2a0; }
.shop-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid #393444; border-radius: 9px; background: #222332; }
.shop-item h3 { margin: 0; color: #f0e7d7; font-size: .87rem; }
.shop-item h3 span { margin-left: 5px; color: #f5cc85; font-size: .78rem; }
.shop-item p { margin-top: 6px; color: #c8bdcc; font-size: .75rem; line-height: 1.4; word-break: keep-all; }
.shop-footer { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }
.shop-status { margin-right: auto; color: #ffe2a3; font-size: .79rem; }
.reset-shop { border-color: #795360; color: #edbbc7; }

.catalog-trigger { border-color: #a47d58; color: #f4dba6; }
.catalog {
  width: min(920px, 100% - 32px);
  max-height: 88vh;
  max-height: 88dvh;
  padding: 0;
  border: 1px solid #796372;
  border-radius: 16px;
  color: #f0e7d7;
  background: linear-gradient(155deg, #2b2435, #181a27 40%);
  box-shadow: 0 24px 70px #070812b3;
  overflow: hidden;
}
.catalog[open] { display: flex; flex-direction: column; }
.catalog::backdrop { background: #090a13ca; }
.catalog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px 24px 13px; }
.catalog-heading h2 { font-size: clamp(1.48rem, 5vw, 2.1rem); }
.catalog-heading p { margin-top: 6px; color: #f1cd8a; font-size: .8rem; font-variant-numeric: tabular-nums; }
.catalog-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 24px 13px; border-bottom: 1px solid #47394d; }
.catalog-filters [aria-pressed="true"] { border-color: #c29265; background: #443241; color: #ffe4ad; }
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  align-content: start;
  gap: 9px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 14px 24px 22px;
  list-style: none;
}
.catalog-grid:focus-visible { outline: 2px solid #d2a874; outline-offset: -3px; }
.catalog-card {
  display: grid;
  justify-items: center;
  gap: 3px;
  grid-template-rows: auto 1fr;
  min-width: 0;
  padding: 6px 6px 9px;
  border: 1px solid #493b51;
  border-radius: 8px;
  background: #30273c;
  text-align: center;
}
.catalog-card.found { border-color: #8b6b58; background: radial-gradient(ellipse at 50% 42%, #514051, #2d293b 72%); }
.catalog-card canvas { display: block; width: 100%; max-width: 108px; height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.catalog-card.unknown canvas { filter: drop-shadow(0 1px 0 #6d597879); }
.catalog-card span { align-self: center; min-height: 2.6em; font-size: .75rem; line-height: 1.3; overflow-wrap: break-word; word-break: keep-all; }
.catalog-card.unknown span { color: #c0a8ca; letter-spacing: .14em; }

@media (max-width: 760px) {
  .game { width: min(100% - 24px, 620px); padding-top: max(13px, env(safe-area-inset-top)); }
  .masthead { margin-bottom: 16px; }
  .layout { grid-template-columns: 1fr; gap: 12px; }
  .forge { padding: 17px; }
  .apple-info { padding: 16px 0; }
  .apple-info p { min-height: auto; }
  .brand-icon { width: 34px; }
  .brand { gap: 8px; }
  .shop-items { grid-template-columns: 1fr; }
  .quiet { min-height: 44px; }
  .route-chip, #restart { top: 12px; }
  .route-chip { left: 12px; }
  #restart { right: 12px; }
  .action-buttons { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  #upgrade, .eat-button { min-height: 51px; }
  .eat-button { margin-top: 0; white-space: normal; line-height: 1.35; }
}

@media (max-width: 380px) {
  .brand-icon { width: 28px; }
  h1 { font-size: 1.36rem; }
  .masthead .quiet { padding-inline: 8px; }
  .forge, .shop { padding: 13px; }
  .shop-item { gap: 8px; padding-inline: 10px; }
}

@media (max-width: 530px) {
  .header-actions #sound { width: 44px; }
  #sound-state { display: none; }
  .catalog { width: calc(100% - 18px); }
  .catalog-heading { padding: 14px 13px 10px; }
  .catalog-filters { padding: 0 13px 10px; }
  .catalog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 10px 13px 14px; gap: 6px; }
  .catalog-card span { font-size: .7rem; }
}
