:root {
  color-scheme: dark;
  --night: #0b1624;
  --night-soft: #17253a;
  --ink: #e7dec9;
  --muted: #a8b3b1;
  --dawn: #ffc866;
  --dawn-pale: #fff0bd;
  --moss: #667a65;
  --danger: #d66961;
  --glass: rgba(9, 20, 31, 0.76);
  --line: rgba(255, 232, 169, 0.28);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", Georgia, serif;
  background: var(--night);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

#app {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background:
    radial-gradient(circle at 50% 28%, #29384b 0, #0b1624 72%);
  color: var(--ink);
}

button, kbd { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.site-back {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 45;
  padding: 8px 11px;
  border: 1px solid rgba(255, 232, 169, .28);
  border-radius: 999px;
  color: #d8ded6;
  background: rgba(7, 18, 28, .72);
  font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .04em;
  text-decoration: none;
  backdrop-filter: blur(10px);
  transition: border-color .18s ease, color .18s ease, transform .18s ease;
}

.site-back:hover,
.site-back:focus-visible {
  border-color: var(--dawn);
  color: var(--dawn-pale);
  outline: 2px solid rgba(255, 240, 189, .8);
  outline-offset: 2px;
  transform: translateY(-1px);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  cursor: grab;
}

#game:active { cursor: grabbing; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 54px);
  background:
    linear-gradient(90deg, rgba(5, 13, 22, .94), rgba(5, 13, 22, .36) 56%, rgba(5, 13, 22, .08)),
    radial-gradient(circle at 78% 28%, rgba(255, 200, 102, .12), transparent 34%);
  opacity: 0;
  visibility: hidden;
  transition: opacity .55s ease, visibility .55s;
}

.screen--open {
  opacity: 1;
  visibility: visible;
}

#title {
  place-items: center start;
}

.title-card {
  width: min(580px, 94vw);
  max-height: calc(100dvh - 36px);
  padding: clamp(26px, 4vw, 54px);
  border: 1px solid var(--line);
  border-radius: 3px 34px 3px 34px;
  background:
    linear-gradient(135deg, rgba(18, 35, 51, .92), rgba(9, 21, 33, .78)),
    var(--glass);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, .46),
    inset 0 1px rgba(255, 255, 255, .05);
  backdrop-filter: blur(18px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 220, 150, .35) transparent;
}

.eyebrow {
  margin: 0 0 13px;
  color: var(--dawn);
  font: 600 11px/1.4 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .24em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fff8e7;
  font-size: clamp(42px, 7vw, 80px);
  font-weight: 500;
  line-height: .98;
  letter-spacing: -.045em;
  text-shadow: 0 4px 32px rgba(255, 200, 102, .16);
}

h2 {
  margin: 0 0 18px;
  color: #fff8e7;
  font-size: clamp(34px, 5vw, 62px);
  font-weight: 500;
}

.role {
  display: inline-flex;
  margin: 28px 0 14px;
  padding: 8px 13px;
  border: 1px solid rgba(255, 200, 102, .44);
  border-radius: 999px;
  color: var(--dawn-pale);
  background: rgba(255, 200, 102, .08);
  font: 600 13px/1.3 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .08em;
}

.story {
  max-width: 48em;
  margin: 7px 0;
  color: #b8c3c0;
  font-size: clamp(13px, 1.35vw, 16px);
  line-height: 1.85;
}

.story--bright { color: #ebe5d6; }

.primary {
  min-width: 210px;
  margin-top: 24px;
  padding: 14px 22px;
  border: 1px solid rgba(255, 225, 155, .7);
  border-radius: 2px 16px 2px 16px;
  color: #16202a;
  background: linear-gradient(135deg, #ffe7a6, #ffc866);
  box-shadow: 0 12px 40px rgba(255, 179, 72, .18);
  font: 700 14px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .08em;
  cursor: pointer;
  transition: transform .18s ease, filter .18s ease, box-shadow .18s ease;
}

.primary:hover,
.primary:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow: 0 16px 48px rgba(255, 179, 72, .3);
  outline: 2px solid #fff1bf;
  outline-offset: 3px;
}

.core-loop {
  display: grid;
  gap: 7px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
  color: #d8ded6;
  font: 600 12px/1.45 ui-sans-serif, system-ui, sans-serif;
}

.core-loop li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.core-loop li > b {
  display: inline-grid;
  flex: 0 0 22px;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(255, 200, 102, .38);
  border-radius: 50%;
  color: var(--dawn);
  font-size: 10px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 15px;
  margin-top: 23px;
  color: #91a09e;
  font: 500 11px/1.5 ui-sans-serif, system-ui, sans-serif;
}

kbd {
  display: inline-block;
  min-width: 24px;
  margin-right: 4px;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: #efe8d8;
  background: rgba(255, 255, 255, .07);
  font: 600 10px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: center;
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
}

.hud--open { opacity: 1; }

.identity {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  display: grid;
  padding-left: 13px;
  border-left: 2px solid var(--dawn);
  filter: drop-shadow(0 2px 7px #07111c);
}

.identity__name {
  color: #fff8e7;
  font-size: 20px;
  line-height: 1.05;
}

.identity__role {
  margin-top: 3px;
  color: #afbbb7;
  font: 600 9px/1.2 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .15em;
}

.mission {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  width: min(360px, 62vw);
  transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 2px 8px #06111c;
}

#chapter {
  display: block;
  margin-bottom: 4px;
  color: var(--dawn);
  font: 700 10px/1.3 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .15em;
}

#objective {
  display: block;
  color: #fff8e7;
  font-size: clamp(13px, 1.5vw, 17px);
  font-weight: 500;
}

.petals {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 9px;
}

.petals i {
  width: 23px;
  height: 7px;
  border: 1px solid rgba(255, 238, 195, .42);
  border-radius: 100% 15% 100% 15%;
  background: rgba(255, 255, 255, .06);
  transform: rotate(-5deg);
  transition: background .8s ease, box-shadow .8s ease, transform .8s ease;
}

.petals i.is-lit {
  background: var(--dawn);
  box-shadow: 0 0 15px rgba(255, 200, 102, .75);
  transform: rotate(5deg) scale(1.08);
}

.stitch-guide {
  position: absolute;
  top: max(92px, calc(env(safe-area-inset-top) + 74px));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 238, 195, .16);
  border-radius: 999px;
  color: #778785;
  background: rgba(7, 18, 28, .52);
  box-shadow: 0 5px 22px rgba(0, 0, 0, .18);
  font: 650 9px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .04em;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.stitch-guide span {
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color .25s ease, transform .25s ease;
}

.stitch-guide span b {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 8px;
}

.stitch-guide > i {
  width: 16px;
  height: 1px;
  background: rgba(255, 238, 195, .18);
}

.stitch-guide span.is-current {
  color: var(--dawn-pale);
  transform: translateY(-1px);
}

.stitch-guide span.is-current b {
  color: #17232b;
  background: var(--dawn);
  box-shadow: 0 0 12px rgba(255, 200, 102, .45);
}

.stitch-guide span.is-done { color: #98b5a4; }

.thread-state {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  top: max(20px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 8px;
  color: #acb8b5;
  font: 600 11px/1.2 ui-sans-serif, system-ui, sans-serif;
  text-shadow: 0 2px 7px #06111c;
}

.thread-state__dot {
  width: 9px;
  height: 9px;
  border: 1px solid rgba(255, 255, 255, .34);
  border-radius: 50%;
  background: #34424b;
  transition: background .3s, box-shadow .3s;
}

.thread-state.is-carrying { color: var(--dawn-pale); }
.thread-state.is-carrying .thread-state__dot {
  background: var(--dawn);
  box-shadow: 0 0 12px rgba(255, 200, 102, .95);
}

.dawnflow {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  top: max(51px, calc(env(safe-area-inset-top) + 33px));
  display: grid;
  grid-template-columns: auto repeat(3, 16px);
  align-items: center;
  gap: 5px;
  color: #70817f;
  font: 700 9px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .12em;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .3s ease, transform .3s ease, color .3s ease;
  text-shadow: 0 2px 7px #06111c;
}

.dawnflow.is-carrying {
  opacity: 1;
  transform: translateY(0);
}

.dawnflow.is-flowing { color: var(--dawn-pale); }

.dawnflow i {
  width: 16px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}

.dawnflow i.is-lit {
  background: var(--dawn);
  box-shadow: 0 0 10px rgba(255, 200, 102, .72);
  transform: scaleX(1.08);
}

.dawnflow small {
  grid-column: 1 / -1;
  justify-self: end;
  color: #7f918f;
  font: 550 8px/1.2 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .03em;
}

.help-button {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  padding: 9px 12px;
  border: 1px solid rgba(255, 238, 195, .26);
  border-radius: 999px;
  color: #dde2d8;
  background: rgba(8, 19, 29, .66);
  font: 650 11px/1 ui-sans-serif, system-ui, sans-serif;
  pointer-events: auto;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.prompt {
  position: absolute;
  z-index: 14;
  left: 50%;
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 38px));
  min-height: 48px;
  padding: 0;
  transform: translateX(-50%) translateY(10px);
  border: 0;
  border-radius: 999px;
  color: #18232a;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  pointer-events: none;
  font: 750 13px/1 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .035em;
  white-space: nowrap;
  transition: opacity .18s ease, transform .18s ease;
}

.prompt--open {
  padding: 13px 20px;
  transform: translateX(-50%) translateY(0);
  background: linear-gradient(135deg, #fff1bd, #ffc866);
  box-shadow: 0 12px 38px rgba(0, 0, 0, .38), 0 0 22px rgba(255, 200, 102, .18);
  opacity: 1;
}

.prompt b {
  display: inline-grid;
  place-items: center;
  min-width: 23px;
  margin-right: 8px;
  padding: 4px 6px;
  border: 1px solid rgba(18, 31, 38, .36);
  border-radius: 5px;
  font: 800 10px/1 ui-monospace, monospace;
}

.hint {
  position: absolute;
  z-index: 13;
  left: 50%;
  bottom: max(108px, calc(env(safe-area-inset-bottom) + 98px));
  max-width: min(520px, 86vw);
  padding: 10px 15px;
  transform: translateX(-50%) translateY(8px);
  border: 1px solid rgba(164, 208, 224, .28);
  border-radius: 3px 14px 3px 14px;
  color: #d9f0f5;
  background: rgba(11, 30, 43, .82);
  font: 600 12px/1.55 ui-sans-serif, system-ui, sans-serif;
  text-align: center;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.hint--open {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.wayfinder {
  position: absolute;
  z-index: 15;
  display: grid;
  justify-items: center;
  gap: 4px;
  width: max-content;
  max-width: 190px;
  transform: translate(-50%, -50%) scale(.9);
  color: #fff0b8;
  opacity: 0;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .75));
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}

.wayfinder--open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.wayfinder__arrow {
  display: block;
  color: var(--dawn);
  font-size: 25px;
  line-height: 1;
  transform-origin: center;
}

.wayfinder__text {
  padding: 5px 8px;
  border: 1px solid rgba(255, 224, 158, .28);
  border-radius: 999px;
  background: rgba(8, 19, 29, .74);
  font: 700 10px/1.2 ui-sans-serif, system-ui, sans-serif;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.toast {
  position: absolute;
  z-index: 16;
  top: 27%;
  left: 50%;
  max-width: min(520px, 82vw);
  transform: translate(-50%, -8px);
  color: #fff1c8;
  font-size: clamp(17px, 2.6vw, 28px);
  text-align: center;
  text-shadow: 0 4px 22px rgba(0, 0, 0, .8);
  opacity: 0;
  transition: opacity .4s, transform .4s;
  pointer-events: none;
}

.toast--open {
  opacity: 1;
  transform: translate(-50%, 0);
}


#pause {
  background: rgba(5, 13, 22, .68);
  backdrop-filter: blur(10px);
}

.small-card {
  width: min(390px, 90vw);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 3px 26px 3px 26px;
  background: var(--glass);
  text-align: center;
}

.small-card h2 { font-size: 32px; }
.small-card p { color: var(--muted); }

#ending {
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 225, 169, .44), transparent 34%),
    linear-gradient(rgba(34, 61, 73, .54), rgba(8, 19, 29, .84));
}

.ending-card {
  text-align: center;
  background: rgba(26, 45, 54, .76);
}

.ending-card h2 { margin-bottom: 6px; }
.ending-card p { color: #dce2d6; line-height: 1.8; }
.ending-line { color: var(--dawn-pale) !important; font-size: 20px; }

.boot {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--night);
  color: #bcc8c4;
  font: 600 12px/1.5 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .08em;
  opacity: 1;
  transition: opacity .7s ease, visibility .7s;
}

.boot--done {
  opacity: 0;
  visibility: hidden;
}

.boot__seed {
  width: 31px;
  height: 42px;
  border: 1px solid rgba(255, 238, 195, .58);
  border-radius: 50% 50% 48% 48% / 65% 65% 35% 35%;
  background: radial-gradient(circle at 50% 65%, #ffc866 0 7%, #263a49 10% 100%);
  box-shadow: 0 0 24px rgba(255, 200, 102, .22);
  animation: breathe 1.8s ease-in-out infinite;
}

.boot-error {
  max-width: 560px;
  margin: 24px;
  padding: 22px;
  border: 1px solid rgba(214, 105, 97, .5);
  background: #17232f;
  text-align: left;
}

.boot-error strong { color: #ffd0c7; }
.boot-error pre { padding: 10px; background: #0b1624; overflow: auto; }

@keyframes breathe {
  50% { transform: translateY(-4px) scale(1.04); box-shadow: 0 0 40px rgba(255, 200, 102, .35); }
}

.touch-controls {
  display: none;
}

@media (hover: none), (pointer: coarse) {
  body.is-playing .touch-controls {
    position: fixed;
    z-index: 24;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    left: max(14px, env(safe-area-inset-left));
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    pointer-events: none;
    user-select: none;
  }

  .touch-pad {
    position: relative;
    width: 168px;
    height: 168px;
    flex: 0 0 168px;
    pointer-events: auto;
  }

  .touch-controls button {
    min-width: 60px;
    min-height: 60px;
    border: 1px solid rgba(255, 232, 176, 0.35);
    border-radius: 50%;
    background: rgba(8, 24, 31, 0.74);
    color: #fff1c8;
    font: 700 11px/1 system-ui, sans-serif;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 5px 18px rgba(0,0,0,.28);
    backdrop-filter: blur(8px);
    touch-action: none;
  }

  .touch-controls button.is-pressed,
  .touch-controls button:active {
    transform: scale(0.92);
    border-color: #ffc866;
    background: rgba(117, 86, 34, 0.82);
  }

  .touch-pad button {
    position: absolute;
  }

  .touch-up { top: 0; left: 54px; }
  .touch-left { top: 54px; left: 0; }
  .touch-down { bottom: 0; left: 54px; }
  .touch-right { top: 54px; right: 0; }

  .touch-actions {
    display: grid;
    grid-template-columns: repeat(2, 64px);
    gap: 8px;
    align-items: end;
    pointer-events: auto;
  }

  .touch-actions button {
    border-radius: 18px;
  }

  .touch-actions .touch-primary {
    min-width: 68px;
    min-height: 68px;
    border-color: rgba(255, 200, 102, 0.78);
    background: rgba(158, 105, 35, 0.82);
    color: white;
    font-size: 13px;
  }

  .help-button {
    display: none;
  }

  .prompt {
    bottom: 160px;
    max-width: min(72vw, 420px);
  }
}

@media (max-width: 700px) {
  .title-card { padding: 27px 24px; }
  .story { line-height: 1.65; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
  .thread-state { top: auto; right: 18px; bottom: 116px; }
  .dawnflow { top: auto; right: 18px; bottom: 145px; }
  .identity__role { display: none; }
  .mission { top: 19px; width: 52vw; }
  .stitch-guide { top: 83px; transform: translateX(-50%) scale(.9); }
  .prompt { bottom: 46px; }
}

@media (max-height: 680px) {
  .screen { padding-block: 12px; }
  .title-card { padding: 22px 28px; }
  h1 { font-size: clamp(38px, 8vh, 58px); }
  .role { margin-top: 17px; }
  .story { line-height: 1.58; }
  .core-loop { margin-top: 13px; gap: 4px; }
  .primary { margin-top: 16px; }
  .controls { margin-top: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .12s !important;
  }
}
