@font-face {
  font-family: "New Rocker";
  src: url("assets/fonts/new-rocker-400-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

/* The carved letters and cut-corner controls share the game's stone and metal palette. */
:root {
  --display-type: "New Rocker", Georgia, serif;
  --stage: #12262c;
  --stage-line: #496367;
  --hand-amber: #f1d7a0;
}

.wordmark {
  display: block;
  width: 100%;
  height: auto;
  color: #ffe4a6;
  font: 400 clamp(2.1rem, 7vw, 5rem) / 1 var(--display-type);
  filter: drop-shadow(0 9px 9px #061218a0);
}

/* Printed endpapers frame the game without entering the playable scene. */
body {
  position: relative;
  isolation: isolate;
  background: #19131c;
}

body::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: clamp(15rem, 23vw, 23rem);
  background:
    linear-gradient(0deg, #19131c 0%, transparent 55%),
    linear-gradient(90deg, #271823f7 0%, #271823f2 25%, #27182342 57%, #27182333 81%, #271823a0 100%),
    linear-gradient(90deg, #19131c, #27182300 62%) min(100%, 84rem) center / min(80%, 72rem) 100% no-repeat,
    url("assets/images/prism-endpaper.webp") right 49% / clamp(38rem, 78vw, 76rem) auto no-repeat;
  pointer-events: none;
}

main::after {
  content: "";
  display: block;
  flex: 1;
  min-height: clamp(5.5rem, 10vw, 10rem);
  margin-top: clamp(.75rem, 2vw, 1.5rem);
  background:
    radial-gradient(ellipse closest-side, #19131c00 24%, #19131c22 65%, #19131c 100%) center / min(100%, 36rem) 100% no-repeat,
    url("assets/images/moth-endpaper.webp") center 47% / min(100%, 36rem) auto no-repeat;
}

#welcome-title { margin: 0; }
.welcome-content { width: min(100%, 730px); padding-inline: clamp(24px, 5vw, 76px); }
#game-brand { width: clamp(132px, 19vw, 245px); margin-bottom: 1rem; }
#game-brand .wordmark { font-size: clamp(1.1rem, 3vw, 2.35rem); }

main:has(#welcome:not([hidden])) > #game-brand { display: none; }
main:has(#game-screen:not([hidden])), main:has(#level-menu:not([hidden])) {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  width: min(calc(100% - 48px), 1160px);
  padding-block: clamp(20px, 4vh, 48px);
}

.welcome-intro {
  max-width: 26ch;
  margin: 1.35rem 0 0;
  font: 500 clamp(1.25rem, 2.2vw, 1.85rem) / 1.2 var(--brush-type);
  font-style: italic;
  color: #f0e7d2;
  text-wrap: pretty;
}

#profile-form { width: min(100%, 22rem); margin-top: clamp(20px, 3vw, 34px); }
#profile-form label[for=nickname] { font: 550 0.93rem / 1.5 system-ui, sans-serif; letter-spacing: 0; }
#profile-form button[type=submit] { font: 650 0.98rem / 1.2 system-ui, sans-serif; border-radius: 8px; }
#home-music-status { max-width: 34ch; margin: .2rem 0 0; font-size: .8rem; }
#nickname::placeholder { color: #adc2bd; opacity: 1; }

#level-menu { padding: clamp(16px, 2.7vw, 36px); border-color: #8e657c; background: #241c28; }
.atlas-layout { grid-template-columns: minmax(250px, .92fr) minmax(0, 1.75fr); }
.atlas-preview { min-height: clamp(320px, 36vw, 440px); }
.atlas-preview h3 { padding: clamp(16px, 2.7vw, 30px); }
#level-grid .atlas-row { gap: .38rem; border-radius: 8px; }
.atlas-indicator { border-radius: 8px; }
.atlas-state { font-size: .75rem; color: #c8d6d2; }
.atlas-header:focus-within h2, #result-title:focus-visible { outline-offset: 4px; }

#menu-title, #stage-name, .atlas-chapter summary, .atlas-preview h3,
#result h2, #settings-title, #hint-title, #hint-map-title, #seal-title {
  font-family: var(--display-type);
  font-weight: 400;
  font-style: normal;
  letter-spacing: .025em;
  line-height: 1.06;
  text-wrap: balance;
}

#menu-title { font-size: clamp(2.45rem, 5.5vw, 5.1rem); color: #ffe8b4; }
.atlas-chapter summary { font-size: clamp(1.2rem, 1.8vw, 1.5rem); color: #efddad; }
.atlas-preview h3 {
  font-size: clamp(2.2rem, 6.2vw, 5.8rem);
  color: #fff2c7;
  text-shadow: 0 4px 12px #08161c;
}
#level-grid .atlas-row { font: 620 .95rem / 1.35 system-ui, sans-serif; border-radius: 0; }
.atlas-indicator {
  border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  background: #71543a;
}
#settings-title, #hint-title, #seal-title { font-size: clamp(2.2rem, 5.8vw, 3.8rem); color: #ffdfa0; }
#hint-map-title { font-size: clamp(1.4rem, 3vw, 1.9rem); color: #bde8cb; }
#result h2 {
  font-size: clamp(2.8rem, 8vw, 6rem);
  color: #ffe3a0;
  text-shadow: 0 5px 16px #101c2390;
}

@media (prefers-reduced-motion: no-preference) {
  #result:not([hidden]) h2 { animation: seal-reveal .32s cubic-bezier(.22,.8,.22,1) both; }
  @keyframes seal-reveal {
    from { opacity: .46; transform: translateY(7px) scale(.94); }
    to { opacity: 1; transform: none; }
  }
}

.game-navigation {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: .55rem;
  margin: 0 0 .7rem;
}

#stage-title {
  display: grid;
  gap: .2rem;
  margin: 0;
  color: var(--paper);
  overflow-wrap: anywhere;
}
#stage-index { font: 650 .75rem / 1.15 system-ui, sans-serif; color: #d5bd89; }
#stage-name { color: #f6ddb3; font-size: clamp(1.8rem, 4.1vw, 3.9rem); text-shadow: 0 2px 12px #201221; }

.game-navigation .controls, .game-navigation .controls[open] { position: relative; padding: 0; }
.controls summary { padding-inline: .75rem; }
.controls #controls-title { font: 600 .9rem / 1.2 system-ui, sans-serif; }
.controls-body {
  position: absolute;
  z-index: 7;
  inset: calc(100% + 10px) 0 auto auto;
  width: min(450px, calc(100vw - 36px));
  padding: 16px;
  max-height: min(64vh, 480px);
  overflow: auto;
  border: 1px solid var(--stage-line);
  border-radius: 10px;
  background: var(--stage);
  box-shadow: 0 12px 28px #071417ab;
}

.controls-body ul:first-child { display: grid; grid-template-columns: repeat(auto-fit, minmax(162px, 1fr)); }
#game-home { min-height: 46px; background: var(--stage); box-shadow: none; }
#field { border-color: #718d87; background: #12292d; }
#status { margin: .7rem 0 .25rem; padding: .7rem .9rem; max-width: none; border: 1px solid var(--stage-line); border-radius: 8px; background: var(--stage); color: #e6eee9; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  column-gap: .55rem;
  row-gap: .6rem;
}
.toolbar-actions, .toolbar-support { gap: .5rem; padding: 0; }
.toolbar-support { margin-inline-start: auto; }
.toolbar-actions { order: 1; }
.toolbar-support { order: 2; }
#next { order: 3; min-width: 0; font: 700 .95rem / 1.2 system-ui, sans-serif; }
#next:disabled { color: #c0cacf; }
#level-picker summary { gap: .45rem; }
#level-picker summary span { font-size: .94em; color: inherit; }
#level-options { width: min(590px, calc(100vw - 48px)); }
#level-options button { min-height: 44px; }
button:not(:disabled), summary { -webkit-tap-highlight-color: #d6eacb35; }
button:focus-visible, summary:focus-visible, input:focus-visible { outline: 2px solid var(--hand-amber); outline-offset: 3px; }

/* Leave the actual hit areas rectangular so the corners don't shrink touch or keyboard targets. */
:is(#profile-form button, .game-navigation button, .toolbar button, .menu-navigation button,
    .result-content button, dialog button:not(#seal-board button), .touch-controls button) {
  position: relative;
  isolation: isolate;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--plate-ink, #f0f5f3);
  text-shadow: none;
}

:is(#profile-form button, .game-navigation button, .toolbar button, .menu-navigation button,
    .result-content button, dialog button:not(#seal-board button), .touch-controls button) {
  &::before, &::after {
    content: "";
    position: absolute;
    z-index: -1;
    pointer-events: none;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  }
  &::before { inset: 0; background: var(--plate-edge, #738e97); }
  &::after {
    inset: 2px 2px 5px;
    background: linear-gradient(163deg, #fff2 0%, transparent 53%), var(--plate-face, #243e4b);
    transition: filter .17s ease, inset .14s ease;
  }
  &:hover:not(:disabled)::after { filter: brightness(1.22); }
  &:active:not(:disabled)::after, &[data-held]::after { inset-block: 4px 2px; filter: brightness(1.3); }
  &:disabled { --plate-edge: #54666d; --plate-face: #28363a; --plate-ink: #c9d1d0; opacity: 1; }
}

#profile-form button[type=submit], #next:not(:disabled), #hint-close {
  --plate-edge: #f5cd78;
  --plate-face: #d5a84f;
  --plate-ink: #231a11;
  min-height: 49px;
  font: 400 1.13rem / 1.2 var(--display-type);
}
#restart, #replay { --plate-edge: #c18e65; --plate-face: #593726; }
#hint-button { --plate-edge: #a894cc; --plate-face: #4b3d64; }
#next:disabled { --plate-ink: #c9d1d0; }

:is(#profile-form button, #profile-form button[type=submit], #welcome-settings, #menu-settings, #game-settings,
    #game-home, #restart, #replay, #hint-button, #next, #next:disabled,
    .toolbar button, .menu-navigation button, .result-content button, dialog button:not(#seal-board button),
    .touch-controls button, #level-options button, #level-options button:disabled):is(:enabled, :disabled) {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--plate-ink, #f0f5f3);
}

#level-options button[aria-current=true] { --plate-edge: #ebcc85; --plate-face: #795d3d; }
#seal-board button { border-radius: 3px; border: 2px solid #687c80; box-shadow: none; }
#seal-board button[aria-pressed=true] { background: #efcb76; border-color: #ffebad; color: #372617; }
.plate-demo-toggle { min-height: 34px; padding-inline: .65rem; }
.game-navigation .controls, #level-picker summary { border-radius: 3px; }
.controls summary, #level-picker summary { padding-block: .64rem; }
#level-picker summary { background: #254d43; border-color: #83b098; box-shadow: none; }

@media (any-pointer: coarse) {
  .plate-demo-toggle { min-height: 44px; }
  .touch-controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: .75rem;
    margin-block: .7rem .4rem;
  }
  .touch-controls .touch-direction { display: grid; grid-template-columns: repeat(2, minmax(48px, 1fr)); }
  .touch-controls .touch-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .touch-controls button {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    --plate-edge: #88a7a9;
    --plate-face: #263f4a;
    --plate-ink: #eef9f6;
    font: 400 clamp(.87rem, 2.6vw, 1.08rem) / 1.09 var(--display-type);
    line-height: 1.2;
  }
  .touch-controls .touch-direction button { font-size: 1.25rem; }
  .touch-controls [data-traveler=jade] { --plate-ink: #d3f9e5; --plate-edge: #7ee0ac; --plate-face: #245e4e; }
  .touch-controls [data-traveler=amber] { --plate-ink: #fff2cc; --plate-edge: #eab76d; --plate-face: #744928; }
  .touch-controls [data-key=KeyE] { --plate-edge: #a3b1de; --plate-face: #384973; }
  .touch-controls [data-key=KeyX]:enabled { --plate-edge: #c1aadd; --plate-face: #564375; }
  .touch-controls button[data-held] { --plate-face: #eaca84; --plate-ink: #1d2826; }
  .touch-controls button:disabled { --plate-edge: #54666d; --plate-face: #28363a; --plate-ink: #c9d1d0; }
  .touch-controls button:active:not(:disabled) { transform: none; }
}

@media (max-width: 660px) {
  main:has(#game-screen:not([hidden])), main:has(#level-menu:not([hidden])) { width: calc(100% - 24px); padding-block: 12px 20px; }
  .atlas-layout { grid-template-columns: minmax(0, 1fr); }
  .atlas-preview { min-height: 0; aspect-ratio: 16/8; }
  .welcome-content { padding: 24px; }
  .welcome-intro { margin-top: 1rem; }
  #game-brand { margin-bottom: .55rem; }
  .game-navigation { grid-template-columns: minmax(0, 1fr) auto auto; }
  .game-navigation .controls, .game-navigation .controls[open] { position: static; }
  .controls-body { inset-inline: 0; width: 100%; }
  #game-home { font-size: .88rem; padding-inline: .6rem; }
  #status { padding: .6rem .7rem; font-size: .88rem; }
  #level-options { width: min(540px, calc(100vw - 24px)); }
  .toolbar-support { margin-inline-start: 0; }
}

@media (max-width: 500px) and (any-pointer: coarse) {
  .touch-controls .touch-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 360px) {
  .game-navigation { grid-template-columns: minmax(0, 1fr) auto; }
  #stage-title { grid-column: 1 / -1; }
  .game-navigation .controls { justify-self: start; }
}

@media (max-width: 520px) {
  body::before {
    background-image:
      linear-gradient(0deg, #19131c 0%, transparent 55%),
      linear-gradient(90deg, #271823fa 0%, #271823de 26%, #27182369 67%, #27182350 100%),
      url("assets/images/prism-endpaper.webp");
    background-position: center, center, 57% 50%;
    background-size: auto, auto, 38rem auto;
  }
  .game-navigation { grid-template-columns: auto minmax(0, 1fr); }
  #stage-title { grid-column: 1 / -1; margin-bottom: .3rem; }
  .game-navigation .controls { justify-self: start; }
  #game-home { justify-self: end; }
  .atlas-preview h3 { font-size: clamp(1.85rem, 7.2vw, 3rem); }
}

@media (prefers-reduced-motion: reduce) {
  button::after, summary::after { transition: none !important; }
}

@media (forced-colors: active) {
  body::before, main::after { display: none; }
}
