:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #5f6d78;
  --panel: #ffffff;
  --line: #d7e0e7;
  --sky: #a8dcff;
  --floor: #f6d47c;
  --accent: #ef5d43;
  --accent-dark: #b83f2b;
  --teal: #159a9c;
  --warning: #f0b429;
  --danger: #d64545;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  display: grid;
  place-items: center;
  background: #eef5f8;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.game-shell {
  width: min(100vw, 430px);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 12px;
}

.game-shell.menu-mode {
  grid-template-rows: 1fr;
}

.game-shell.demo-mode,
.game-shell.play-mode {
  grid-template-rows: auto 1fr auto;
}

.hud,
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 8px;
}

.hud {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 8px 24px rgb(23 33 43 / 8%);
}

.hud-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.hud-actions button {
  min-width: 78px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.menu-mode .hud,
.menu-mode .controls {
  display: none;
}

.play-area {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.menu-mode .play-area {
  min-height: calc(100vh - 24px);
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.hud p:not(.label) {
  margin: 2px 0 0;
  font-size: 1.45rem;
  font-weight: 800;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--teal);
  color: white;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button:active {
  transform: translateY(1px);
}

#restart {
  background: var(--accent);
}

#game {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 250px);
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sky);
  box-shadow: 0 12px 30px rgb(23 33 43 / 12%);
}

.menu-mode #game {
  display: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(#a8dcff 0%, #eef9ff 58%, #f6d47c 100%);
  box-shadow: 0 12px 30px rgb(23 33 43 / 12%);
  overflow: hidden;
}

.screen.hidden,
.demo-label.hidden,
.button-cue.hidden,
.result-panel.hidden {
  display: none;
}

.certificate-screen {
  background: #d9e5df;
}

.title-cat {
  width: min(68%, 250px);
  justify-self: center;
  filter: drop-shadow(0 10px 12px rgb(23 33 43 / 18%));
}

.screen h1,
.screen h2 {
  margin: 0;
  text-align: center;
  letter-spacing: 0;
}

.screen h1 {
  font-size: clamp(1.9rem, 9vw, 2.55rem);
  line-height: 1.05;
}

.screen h1 span {
  font-size: 1rem;
}

.menu-actions {
  display: grid;
  gap: 10px;
}

.menu-actions button,
.story-card button,
.secondary {
  min-height: 52px;
}

.privacy-link {
  justify-self: center;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.secondary {
  background: #52616d;
}

.hard-mode-entry {
  background: #25333f;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stage-grid button {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  padding: 0;
  overflow: hidden;
}

.stage-grid button[disabled] {
  background: #a9b5bd;
  color: #eef5f8;
}

.stage-grid button.locked-stage {
  background: #394752;
  color: #fff;
}

.stage-grid button b {
  position: absolute;
  inset: auto -22px 6px auto;
  width: 92px;
  padding: 3px 0;
  background: var(--warning);
  color: var(--ink);
  font-size: 0.62rem;
  letter-spacing: 0;
  transform: rotate(-16deg);
  box-shadow: 0 3px 8px rgb(23 33 43 / 18%);
}

.stage-grid small {
  display: block;
  margin-top: 2px;
  font-size: 0.66rem;
  font-weight: 800;
  opacity: 0.82;
}

.ending-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
}

.ending-actions button {
  min-height: 46px;
  background: #25333f;
}

.ending-actions button:disabled {
  cursor: not-allowed;
  background: #8a98a2;
  opacity: 0.62;
}

.unlock-status {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.story-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgb(23 33 43 / 14%);
}

.certificate-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px 20px 22px;
  border: 2px solid #2e5f52;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgb(46 95 82 / 0.08) 0 2px, transparent 2px 100%),
    linear-gradient(#fbfaf2, #f6f0dc);
  background-size: 22px 100%, auto;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 18px 38px rgb(23 33 43 / 18%), inset 0 0 0 7px rgb(46 95 82 / 0.12);
}

.certificate-watermark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 430px;
  margin: 0;
  color: rgb(46 95 82 / 0.10);
  font-size: 2.2rem;
  font-weight: 1000;
  line-height: 1;
  text-transform: uppercase;
  transform: translate(-50%, -50%) rotate(-12deg);
}

.certificate-kicker,
.certificate-card h2,
.certificate-card p:not(.certificate-watermark),
.certificate-lines {
  position: relative;
  margin: 0;
}

.certificate-kicker {
  display: grid;
  place-items: center;
  width: 118px;
  height: 42px;
  border: 2px solid #2e5f52;
  background: #2e5f52;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 1000;
  letter-spacing: 0.16em;
}

.certificate-card h2 {
  color: #173d35;
  font-size: clamp(1.35rem, 7vw, 1.95rem);
  line-height: 1.2;
}

.certificate-lines {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 12px 0 4px;
}

.certificate-lines div {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: end;
  gap: 8px;
  text-align: left;
}

.certificate-lines dt {
  color: #2e5f52;
  font-size: 0.82rem;
  font-weight: 900;
}

.certificate-lines dd {
  min-height: 30px;
  margin: 0;
  padding: 0 4px 5px;
  border-bottom: 2px solid #78958c;
  color: var(--ink);
  font-weight: 900;
}

.certificate-card p:not(.certificate-watermark):not(.certificate-kicker) {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.55;
}

.certificate-message {
  max-width: 290px;
}

.certificate-date {
  justify-self: end;
  padding-right: 8px;
}

.certificate-seal {
  position: absolute;
  right: 24px;
  bottom: 82px;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 4px double rgb(214 69 69 / 0.82);
  border-radius: 50%;
  color: rgb(214 69 69 / 0.86);
  font-size: 1rem;
  font-weight: 1000;
  transform: rotate(-10deg);
}

#story-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

#story-text {
  min-height: 4.5rem;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.45;
  white-space: pre-line;
}

.story-visual {
  position: relative;
  height: 150px;
  border-radius: 8px;
  background: #dff4ff;
  overflow: hidden;
}

.story-visual::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: 32px;
  height: 8px;
  background: #314a59;
}

.story-visual::after {
  content: "";
  position: absolute;
  left: var(--cart-x, 64px);
  top: 22px;
  width: 48px;
  height: 24px;
  background: var(--accent);
  box-shadow: 0 26px 0 -6px #25333f;
}

.story-visual .beam {
  position: absolute;
  left: var(--load-x, 78px);
  top: 105px;
  width: 86px;
  height: 16px;
  border: 4px solid #43525c;
  background: #6f7f89;
  transform: rotate(var(--load-rot, 0deg));
}

.story-visual .rope {
  position: absolute;
  left: calc(var(--cart-x, 64px) + 24px);
  top: 50px;
  width: 5px;
  height: 72px;
  background: #25333f;
  transform-origin: top;
  transform: rotate(var(--rope-rot, 0deg));
}

.story-visual.scene-2,
.story-visual.scene-3 {
  --cart-x: 132px;
  --load-x: 104px;
  --rope-rot: -14deg;
  --load-rot: -8deg;
}

.story-visual.scene-3 {
  --cart-x: 178px;
  --load-x: 170px;
  --rope-rot: 2deg;
  --load-rot: 1deg;
}

.story-visual .pulse {
  position: absolute;
  right: 42px;
  top: 62px;
  color: var(--accent);
  font-weight: 900;
  font-size: 1.6rem;
}

.demo-label {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.88);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 8px 18px rgb(23 33 43 / 14%);
}

.result-panel {
  position: absolute;
  left: 38px;
  right: 38px;
  top: 50%;
  z-index: 4;
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 8px;
  background: rgb(255 255 255 / 0.94);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 16px 36px rgb(23 33 43 / 24%);
  transform: translateY(-50%);
}

.result-panel h2,
.result-panel p {
  margin: 0;
}

.result-panel h2 {
  font-size: 2rem;
}

.result-panel p {
  color: var(--muted);
  font-weight: 800;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-actions button {
  min-height: 52px;
  padding: 0 10px;
}

.result-actions .demo-watch {
  grid-column: 1 / -1;
  background: var(--warning);
  color: var(--ink);
}

.result-actions .auto-clear {
  grid-column: 1 / -1;
  background: #159a9c;
  color: #fff;
}

.result-actions .demo-watch.hidden,
.result-actions .auto-clear.hidden {
  display: none;
}

.controls {
  position: relative;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, 58px);
  grid-template-areas:
    ". up ."
    "left down right";
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.hard-mode .controls {
  grid-template-columns: 1fr;
  grid-template-rows: 68px;
  grid-template-areas: "right";
}

.hard-mode .dir-left,
.hard-mode .dir-up,
.hard-mode .dir-down {
  display: none;
}

.hard-mode .controls button {
  min-height: 68px;
  font-size: 2rem;
}

.controls button {
  min-height: 58px;
  background: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
  padding: 0;
}

.controls button.is-pressed {
  transform: translateY(1px);
  box-shadow: inset 0 0 0 3px rgb(255 255 255 / 0.38);
}

.dir-up {
  grid-area: up;
  background: #52616d;
}

.dir-left {
  grid-area: left;
  background: var(--accent-dark);
}

.controls .dir-left.is-pressed,
.controls .dir-right.is-pressed {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 0 0 4px rgb(214 69 69 / 24%), inset 0 0 0 3px rgb(255 255 255 / 0.45);
}

.dir-down {
  grid-area: down;
  background: #52616d;
}

.dir-right {
  grid-area: right;
  background: var(--teal);
}

.button-cue {
  position: absolute;
  right: 4px;
  bottom: 66px;
  z-index: 2;
  min-width: 92px;
  padding: 8px 12px;
  border: 3px solid var(--danger);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.98);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 8px 18px rgb(23 33 43 / 18%);
  pointer-events: none;
}

.button-cue::after {
  content: "";
  position: absolute;
  right: 18px;
  bottom: -13px;
  width: 18px;
  height: 18px;
  border-right: 3px solid var(--danger);
  border-bottom: 3px solid var(--danger);
  background: rgb(255 255 255 / 0.98);
  transform: rotate(45deg);
}

.policy-page {
  display: block;
  min-height: 100vh;
  padding: 18px;
  overflow: auto;
  background: #eef5f8;
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.policy-card {
  max-width: 760px;
  margin: 0 auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgb(23 33 43 / 10%);
}

.policy-card,
.policy-card * {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.policy-card h1,
.policy-card h2,
.policy-card p {
  margin: 0;
}

.policy-card h1 {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  line-height: 1.15;
}

.policy-card h2 {
  margin-top: 22px;
  font-size: 1.15rem;
}

.policy-card p {
  margin-top: 10px;
  color: #2e3a44;
  line-height: 1.7;
}

.policy-card a {
  color: var(--teal);
  font-weight: 800;
}

.policy-date {
  font-weight: 800;
}
