:root {
  --ink: #554538;
  --paper: #fffaf0;
  --coral: #ef8d72;
  --yellow: #f5c85a;
  --shadow: rgba(102, 72, 53, 0.16);
}

* { box-sizing: border-box; }

html { background: #f9edd9; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 10%, rgba(255,255,255,.85) 0 4%, transparent 17%),
    radial-gradient(circle at 85% 86%, rgba(255,255,255,.65) 0 3%, transparent 15%),
    linear-gradient(135deg, #fff9ed, #f8e8d1);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 4px solid #4a91c6; outline-offset: 3px; }

.app-shell { width: min(100%, 980px); min-height: 100svh; margin: 0 auto; padding: 14px clamp(14px, 3vw, 32px) 34px; }
.app-header { display: grid; grid-template-columns: minmax(76px, 1fr) auto minmax(76px, 1fr); align-items: center; gap: 8px; min-height: 72px; }
.title-wrap { text-align: center; }
.eyebrow, .section-heading p, .play-heading p { margin: 0; color: #9c745c; font-size: clamp(.74rem, 2vw, .9rem); font-weight: 800; letter-spacing: .08em; }
h1 { margin: 1px 0 0; color: #5b5347; font-size: clamp(1.48rem, 5vw, 2.25rem); letter-spacing: .06em; }
h2 { margin: 0; line-height: 1.25; }

.back-button, .settings-button {
  min-height: 44px; border: 0; border-radius: 16px; padding: 7px 10px; background: rgba(255,255,255,.78);
  box-shadow: 0 3px 0 rgba(134, 98, 72, .16); font-size: clamp(.72rem, 2.4vw, .88rem); font-weight: 800;
}
.back-button { justify-self: start; }
.settings-button { justify-self: end; line-height: 1.18; color: #745f55; }
.is-hidden { display: none !important; }

.screen { max-width: 900px; margin: 0 auto; padding-top: clamp(20px, 5vh, 54px); }
.home-screen { display: grid; justify-items: center; gap: clamp(24px, 5vh, 48px); }
.welcome-card { width: min(100%, 540px); padding: 26px 18px 22px; border: 3px solid rgba(255,255,255,.92); border-radius: 38px 42px 35px 45px; text-align: center; background: rgba(255,255,255,.72); box-shadow: 0 11px 24px var(--shadow); transform: rotate(-.45deg); }
.welcome-card h2 { font-size: clamp(1.5rem, 6vw, 2.4rem); }
.welcome-card p { margin: 12px 0 0; font-size: clamp(1rem, 3.5vw, 1.25rem); font-weight: 700; line-height: 1.75; }
.welcome-sparkles { margin-bottom: 5px; color: var(--yellow); font-size: 1.35rem; letter-spacing: .22em; }

.home-choices { display: grid; width: min(100%, 690px); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(14px, 4vw, 32px); }
.home-choice, .course-choice { min-width: 64px; border: 3px solid rgba(255,255,255,.9); border-radius: 34px 28px 37px 31px; box-shadow: 0 8px 0 rgba(121, 91, 66, .17), 0 15px 23px rgba(115, 77, 53, .1); transition: transform .16s ease, box-shadow .16s ease; }
.home-choice:hover, .course-choice:hover { transform: translateY(-3px) rotate(.3deg); box-shadow: 0 10px 0 rgba(121, 91, 66, .17), 0 18px 25px rgba(115, 77, 53, .12); }
.home-choice:active, .course-choice:active { transform: translateY(4px); box-shadow: 0 3px 0 rgba(121, 91, 66, .17); }
.home-choice { min-height: min(40vw, 220px); padding: 20px 12px 16px; font-size: clamp(1.42rem, 5vw, 2.15rem); font-weight: 900; }
.home-choice small { display: block; margin-top: 7px; font-size: clamp(.76rem, 2.6vw, 1rem); font-weight: 700; line-height: 1.45; }
.choice-picture { display: block; margin-bottom: 5px; font-size: clamp(2.6rem, 10vw, 4.8rem); filter: drop-shadow(0 4px 1px rgba(99,72,55,.17)); }
.road-choice { background: linear-gradient(145deg, #d6eff4, #a9dbdf); }
.shape-choice { background: linear-gradient(145deg, #ffe9a8, #f8cf7c); }

.course-screen { max-width: 800px; }
.section-heading, .play-heading { text-align: center; }
.section-heading h2, .play-heading h2 { margin-top: 4px; font-size: clamp(1.45rem, 5vw, 2.2rem); }
.course-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(10px, 2vw, 18px); margin-top: clamp(24px, 6vh, 54px); }
.course-choice { min-height: 180px; padding: 18px 10px; background: rgba(255,255,255,.86); }
.course-choice:nth-child(1) { background: linear-gradient(155deg, #dff2de, #b8ddbd); }
.course-choice:nth-child(2) { background: linear-gradient(155deg, #dcedf6, #aed8e8); }
.course-choice:nth-child(3) { background: linear-gradient(155deg, #ffe6c5, #f6c48f); }
.course-icon { display: block; height: 64px; margin-bottom: 13px; font-size: 3.1rem; line-height: 1; }
.course-choice strong { display: block; font-size: clamp(1.08rem, 3.5vw, 1.45rem); }
.course-choice small { display: block; margin-top: 9px; font-size: clamp(.7rem, 2.3vw, .88rem); font-weight: 700; line-height: 1.4; }

.play-screen { max-width: 900px; padding-top: 10px; }
.trace-instruction { margin: 9px 0 10px; text-align: center; font-size: clamp(1rem, 3.1vw, 1.28rem); font-weight: 800; }
.trace-board { position: relative; overflow: hidden; border: 4px solid rgba(255,255,255,.92); border-radius: clamp(22px, 5vw, 38px); background: var(--paper); box-shadow: 0 10px 23px var(--shadow); }
#trace-svg { display: block; width: 100%; max-height: min(66svh, 620px); touch-action: none; user-select: none; }
.trace-status { min-height: 2em; margin: 12px 0 0; text-align: center; color: #725e51; font-size: clamp(.94rem, 3vw, 1.15rem); font-weight: 800; }

.svg-sky { fill: #fbf7e9; }
.scene-hill { fill: #cce6c2; opacity: .72; }
.scene-hill-far { fill: #dbeec8; opacity: .72; }
.scene-cloud { fill: #fff; opacity: .78; }
.track-shadow { fill: none; stroke: #e6d6bc; stroke-linecap: round; stroke-linejoin: round; }
.trace-path { fill: none; stroke: #f8d97b; stroke-linecap: round; stroke-linejoin: round; opacity: .96; }
.progress-path { fill: none; stroke: #67b8be; stroke-linecap: round; stroke-linejoin: round; transition: stroke-dashoffset .08s linear; }
.start-marker { fill: #58aabe; stroke: #fffaf0; stroke-width: 10; filter: drop-shadow(0 3px 2px rgba(73,93,84,.22)); }
.end-marker { fill: #f4bd49; stroke: #fffaf0; stroke-width: 9; filter: drop-shadow(0 3px 2px rgba(102,80,50,.22)); }
.marker-label { fill: #6d6154; font-size: 28px; font-weight: 800; paint-order: stroke; stroke: #fffaf0; stroke-width: 8; stroke-linejoin: round; }
.start-pulse { fill: none; stroke: #66b9c7; stroke-width: 7; opacity: .66; transform-origin: center; animation: markerPulse 1.7s ease-in-out infinite; }
.hint-dot { fill: #fff9bd; stroke: #e6ad3e; stroke-width: 4; opacity: 0; }
.hints-showing .hint-dot { animation: hintGlow 1.2s ease-in-out both; }
.recovery-dot { fill: #78bddd; stroke: #fffdf6; stroke-width: 9; filter: drop-shadow(0 2px 2px rgba(57,99,125,.22)); }
.recovery-label { fill: #356f89; font-size: 28px; font-weight: 900; paint-order: stroke; stroke: #fffdf6; stroke-width: 8; stroke-linejoin: round; }
.scene-item { opacity: .82; transition: opacity .25s ease; }
.complete-art { opacity: 0; transform-box: fill-box; transform-origin: center; }
.is-complete .complete-art { opacity: 1; animation: gentleBounce .72s ease-out both; }
.is-complete .scene-item { opacity: 1; }
.scene-line { fill: none; stroke: #9d775c; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.scene-detail { fill: #f1a578; stroke: #9d775c; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.scene-leaf { fill: #83bd8c; stroke: #6d976f; stroke-width: 7; }
.scene-window { fill: #a8dbe2; stroke: #9d775c; stroke-width: 9; }
.scene-star { fill: #f7c84e; stroke: #d68d47; stroke-width: 8; stroke-linejoin: round; }
.shape-complete-fill { stroke: #9d775c; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; opacity: .88; }
.shape-complete-line { fill: none; stroke-width: 46; stroke-linecap: round; stroke-linejoin: round; opacity: .88; }

.success-panel { position: absolute; inset: 0; z-index: 3; display: grid; place-content: center; gap: 3px; padding: 24px; text-align: center; background: rgba(255, 250, 239, .88); animation: successFade .35s ease-out both; }
.hanamaru { width: clamp(88px, 16vw, 132px); height: clamp(88px, 16vw, 132px); margin: 0 auto; border: clamp(7px, 1.4vw, 12px) solid var(--coral); border-radius: 50%; color: var(--coral); font-family: Georgia, serif; font-size: clamp(4rem, 10vw, 7rem); font-weight: 900; line-height: .95; transform: rotate(-12deg); }
.success-overline { margin: 7px 0 0; color: #a37062; font-weight: 900; }
.success-panel h2 { color: #d76f59; font-size: clamp(2rem, 8vw, 3.5rem); letter-spacing: .04em; }
.success-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.success-actions button, .dialog-done { min-width: 132px; min-height: 64px; border: 3px solid rgba(255,255,255,.85); border-radius: 21px; padding: 10px 18px; background: #f4bf52; box-shadow: 0 5px 0 #d99c37; color: #614c30; font-size: clamp(1rem, 3.4vw, 1.25rem); font-weight: 900; }
.success-actions button:first-child { background: #a4d4b0; box-shadow: 0 5px 0 #70af80; color: #3d664a; }
.success-actions button:active, .dialog-done:active { transform: translateY(4px); box-shadow: 0 1px 0 transparent; }
.confetti-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.confetti { position: absolute; top: -12%; left: var(--left); width: 11px; height: 18px; border-radius: 4px; background: var(--color); transform: rotate(var(--turn)); animation: confettiFall var(--speed) cubic-bezier(.18,.65,.43,1) forwards; }

.settings-dialog { width: min(calc(100% - 28px), 500px); border: 4px solid rgba(255,255,255,.9); border-radius: 30px; padding: 22px; color: var(--ink); background: #fffaf0; box-shadow: 0 20px 55px rgba(66,45,36,.28); }
.settings-dialog::backdrop { background: rgba(79, 64, 54, .38); backdrop-filter: blur(2px); }
.settings-topline { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-topline p { margin: 0; color: #9a735f; font-size: .83rem; font-weight: 800; }
.dialog-close { min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: #f5ddcd; color: #765e52; font-size: 1.8rem; line-height: 1; }
.settings-dialog h2 { margin: 3px 0 18px; font-size: clamp(1.26rem, 5vw, 1.65rem); }
.settings-dialog fieldset { display: grid; gap: 12px; margin: 0; border: 0; padding: 0; }
.settings-dialog legend { margin-bottom: 9px; font-weight: 900; }
.mode-option { display: grid; grid-template-columns: 28px 1fr; gap: 9px; align-items: start; min-height: 62px; border: 2px solid #ead6bd; border-radius: 16px; padding: 11px; background: #fff; cursor: pointer; }
.mode-option:has(input:checked) { border-color: #71b8bc; background: #ecf8f5; }
.mode-option input { width: 21px; height: 21px; margin: 2px 0 0; accent-color: #549eab; }
.mode-option strong, .mode-option small { display: block; }
.mode-option strong { font-size: 1.08rem; }
.mode-option small { margin-top: 4px; color: #766c65; line-height: 1.35; }
.settings-note { margin: 16px 0; color: #766c65; font-size: .86rem; line-height: 1.55; }
.dialog-done { display: block; width: min(100%, 220px); margin: 0 auto; }

@keyframes markerPulse { 50% { opacity: .16; transform: scale(1.34); } }
@keyframes hintGlow { 0%,100% { opacity: 0; transform: scale(.7); } 40%,65% { opacity: .95; transform: scale(1.12); } }
@keyframes gentleBounce { 0% { transform: scale(.72); } 55% { transform: scale(1.09) rotate(-2deg); } 78% { transform: scale(.96) rotate(1deg); } 100% { transform: scale(1); } }
@keyframes successFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes confettiFall { to { transform: translateY(122vh) rotate(calc(var(--turn) + 420deg)); opacity: .1; } }

@media (max-width: 480px) {
  .app-shell { padding-inline: 10px; }
  .app-header { grid-template-columns: 72px 1fr 72px; }
  .back-button, .settings-button { padding-inline: 5px; }
  .course-choices { grid-template-columns: 1fr; margin-top: 22px; }
  .course-choice { display: grid; grid-template-columns: 65px 1fr; column-gap: 10px; align-items: center; min-height: 102px; padding: 12px; text-align: left; }
  .course-icon { grid-row: span 2; height: auto; margin: 0; font-size: 3rem; text-align: center; }
  .course-choice small { margin: 2px 0 0; }
  .trace-board { border-radius: 24px; }
}

@media (max-height: 610px) and (orientation: landscape) {
  .app-shell { padding-top: 5px; padding-bottom: 12px; }
  .app-header { min-height: 54px; }
  .screen { padding-top: 8px; }
  .welcome-card { padding: 12px; }
  .welcome-card p { margin-top: 5px; line-height: 1.35; }
  .home-choices { gap: 14px; }
  .home-choice { min-height: 132px; padding: 9px; }
  .choice-picture { font-size: 2.3rem; }
  #trace-svg { max-height: 67svh; }
}

@media (max-width: 480px), (max-height: 610px) and (orientation: landscape) {
  .success-panel { gap: 0; padding: 8px; }
  .hanamaru {
    width: clamp(54px, 18vw, 64px);
    height: clamp(54px, 18vw, 64px);
    border-width: 5px;
    font-size: clamp(2.7rem, 12vw, 3.35rem);
  }
  .success-overline { margin-top: 2px; font-size: .76rem; line-height: 1.1; }
  .success-panel h2 { font-size: clamp(1.4rem, 6vw, 1.85rem); line-height: 1.05; }
  .success-actions { width: min(100%, 290px); margin: 6px auto 0; flex-wrap: nowrap; gap: 6px; }
  .success-actions button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 64px;
    padding: 7px 5px;
    border-width: 2px;
    border-radius: 17px;
    font-size: clamp(.86rem, 3.6vw, 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .hints-showing .hint-dot { opacity: .92; }
}
