:root {
  color-scheme: light;
  --deep: #173f47;
  --ocean: #0c7c83;
  --aqua: #56c8c3;
  --foam: #f7fbf5;
  --sand: #f6efd9;
  --coral: #ee725d;
  --gold: #efc75e;
  --lavender: #a799c9;
  --ink: #173f47;
  --muted: #62757c;
  --white: #ffffff;
  --shadow: 0 18px 45px rgba(22, 64, 84, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--foam); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next Rounded", "Avenir Next", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 20%, rgba(142, 216, 208, 0.28), transparent 32rem),
    linear-gradient(180deg, #edfafa 0%, #fffaf0 76%, #fff6e3 100%);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; }
button:focus-visible, [role="gridcell"]:focus-visible { outline: 4px solid #f6a800; outline-offset: 3px; }

.water-light {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background-image:
    radial-gradient(ellipse at 20% 0%, transparent 0 50%, rgba(255,255,255,.5) 51% 53%, transparent 54%),
    radial-gradient(ellipse at 72% 4%, transparent 0 48%, rgba(255,255,255,.42) 49% 51%, transparent 52%);
  background-size: 240px 110px, 300px 130px;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: calc(68px + var(--safe-top));
  padding: calc(8px + var(--safe-top)) clamp(16px, 4vw, 44px) 8px;
  background: rgba(244, 251, 248, 0.88);
  border-bottom: 1px solid rgba(23, 60, 93, 0.09);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0;
  color: var(--deep);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.brand img { width: 48px; height: 48px; object-fit: cover; border-radius: 50%; border: 2px solid white; box-shadow: 0 4px 14px rgba(40, 79, 105, .18); }
.brand span { display: grid; line-height: 1; }
.brand strong { font-family: Georgia, serif; font-size: 1.2rem; letter-spacing: .01em; }
.brand small { margin-top: 4px; color: var(--ocean); font-size: .7rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.header-actions { display: flex; gap: 10px; align-items: center; }
.offline-pill { padding: 7px 11px; border: 1px solid rgba(29, 113, 130, .22); border-radius: 999px; color: var(--ocean); background: rgba(255,255,255,.7); font-size: .74rem; font-weight: 800; }
.offline-pill.offline { color: var(--deep); background: #f8e9ad; }
.icon-button, .close-button { width: 40px; height: 40px; border: 0; border-radius: 50%; color: white; background: var(--deep); cursor: pointer; font-weight: 900; font-size: 1.05rem; }

main { position: relative; width: min(1180px, 100%); margin: 0 auto; padding: clamp(18px, 4vw, 46px) clamp(15px, 4vw, 42px) calc(36px + var(--safe-bottom)); }
.trail-view, .game-view { animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.trail-hero {
  overflow: hidden;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  align-items: center;
  min-height: 280px;
  padding: clamp(24px, 5vw, 58px);
  border-radius: 32px;
  color: white;
  background:
    radial-gradient(circle at 78% 8%, rgba(255,255,255,.28), transparent 22%),
    linear-gradient(135deg, #173f47 0%, #075966 52%, #0c7c83 100%);
  box-shadow: var(--shadow);
}

.trail-hero::after { content: ""; position: absolute; inset: auto -5% -36% 28%; height: 75%; border: 2px solid rgba(255,255,255,.2); border-radius: 50%; transform: rotate(-8deg); }
.trail-hero h1 { max-width: 620px; margin: 8px 0 12px; font-family: Georgia, serif; font-size: clamp(2.15rem, 6vw, 4.6rem); line-height: .98; font-weight: 500; }
.trail-hero p:not(.eyebrow) { max-width: 560px; margin: 0; color: rgba(255,255,255,.87); font-size: clamp(1rem, 2vw, 1.22rem); line-height: 1.55; }
.hero-crew { position: relative; z-index: 2; min-height: 260px; }
.crew-card { position: absolute; overflow: hidden; margin: 0; border: 3px solid rgba(255,255,255,.9); border-radius: 22px; background: var(--sand); box-shadow: 0 13px 28px rgba(3,45,52,.26); }
.crew-card img { display: block; width: 100%; height: calc(100% - 24px); object-fit: contain; background: #fbf8f1; }
.crew-card figcaption { height: 24px; padding: 4px 7px; color: var(--deep); background: rgba(247,251,245,.96); font-size: .63rem; font-weight: 900; letter-spacing: .08em; text-align: center; text-transform: uppercase; }
.crew-castlebury { z-index: 5; top: 30px; left: 50%; width: 174px; height: 194px; transform: translateX(-50%) rotate(-1deg); }
.crew-ripple { z-index: 3; top: 4px; left: 0; width: 142px; height: 118px; transform: rotate(-4deg); }
.crew-dottie { z-index: 2; top: 0; right: 0; width: 145px; height: 120px; transform: rotate(4deg); }
.crew-shelly { z-index: 4; bottom: 0; left: 8px; width: 142px; height: 126px; transform: rotate(3deg); }
.crew-snap { z-index: 4; right: 4px; bottom: 0; width: 160px; height: 116px; transform: rotate(-3deg); }
.eyebrow { margin: 0; color: var(--ocean); font-size: .72rem; font-weight: 900; letter-spacing: .15em; text-transform: uppercase; }
.trail-hero .eyebrow { color: #beece6; }

.progress-card { margin: 22px 0; padding: 18px 20px; border-radius: 20px; background: rgba(255,255,255,.76); box-shadow: 0 8px 30px rgba(22,64,84,.08); }
.progress-copy { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: .9rem; }
.progress-copy span { color: var(--muted); font-weight: 700; }
.progress-copy strong { color: var(--ocean); }
.progress-track { overflow: hidden; height: 9px; border-radius: 99px; background: #d8ebe7; }
.progress-track span { display: block; width: 10%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--coral), var(--gold)); transition: width .45s ease; }

.trail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.trail-stop { position: relative; display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center; min-height: 92px; padding: 15px; border: 1px solid rgba(23,60,93,.1); border-radius: 22px; color: var(--ink); background: rgba(255,255,255,.82); box-shadow: 0 9px 26px rgba(22,64,84,.08); cursor: pointer; text-align: left; transition: transform .18s ease, box-shadow .18s ease; }
.trail-stop:hover { transform: translateY(-2px); box-shadow: 0 13px 30px rgba(22,64,84,.13); }
.trail-stop.locked { cursor: default; opacity: .54; box-shadow: none; }
.trail-stop.complete { border-color: rgba(29,113,130,.32); background: linear-gradient(135deg, white, #eefbf7); }
.stop-number { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; color: var(--deep); background: var(--stop-color, var(--aqua)); font-size: 1.45rem; }
.trail-stop strong, .trail-stop small { display: block; }
.trail-stop strong { margin-bottom: 4px; font-family: Georgia, serif; font-size: clamp(1rem, 2vw, 1.2rem); }
.trail-stop small { color: var(--muted); line-height: 1.25; }
.stop-state { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: white; background: var(--ocean); font-weight: 900; }
.locked .stop-state { color: var(--muted); background: #e7eeee; }

.text-button { display: block; margin: 24px auto 0; padding: 11px 14px; border: 0; color: var(--muted); background: transparent; text-decoration: underline; cursor: pointer; }

.game-topline { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.back-button, .small-button { border: 1px solid rgba(23,60,93,.13); border-radius: 999px; color: var(--deep); background: rgba(255,255,255,.75); cursor: pointer; font-weight: 800; }
.back-button { padding: 10px 15px; }
.small-button { padding: 8px 12px; font-size: .76rem; }
.theme-count { color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.theme-heading { display: grid; grid-template-columns: 112px 1fr; gap: 20px; align-items: center; margin-bottom: 20px; }
.theme-guide-art { position: relative; overflow: visible; width: 112px; height: 112px; border: 3px solid white; border-radius: 28px; background: var(--sand); box-shadow: 0 10px 25px rgba(22,64,84,.14); }
.theme-guide-art img { display: block; width: 100%; height: 100%; border-radius: 25px; object-fit: contain; background: #fbf8f1; }
.theme-icon { position: absolute; right: -9px; bottom: -9px; display: grid; place-items: center; width: 42px; height: 42px; border: 3px solid white; border-radius: 14px; background: var(--theme-color, var(--lavender)); font-size: 1.35rem; box-shadow: 0 5px 13px rgba(23,60,93,.16); }
.theme-heading h1 { margin: 3px 0 4px; font-family: Georgia, serif; font-size: clamp(1.8rem, 4vw, 3.25rem); font-weight: 500; line-height: 1.05; }
.theme-heading p:last-child { margin: 0; color: var(--muted); }
.theme-heading .guide-label { display: inline-flex; gap: .25em; width: auto; margin-top: 9px; padding: 6px 10px; border-radius: 999px; color: var(--deep); background: var(--sand); font-size: .76rem; font-weight: 800; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.52fr) minmax(245px, .66fr); gap: 20px; align-items: start; }
.puzzle-card, .word-card { border: 1px solid rgba(23,60,93,.1); border-radius: 28px; background: rgba(255,255,255,.88); box-shadow: var(--shadow); }
.puzzle-card { padding: clamp(13px, 2.4vw, 24px); touch-action: none; }
.word-card { padding: 22px; }
.puzzle-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.puzzle-toolbar p { margin: 0; color: var(--ocean); font-weight: 900; }
.grid-wrap { width: min(100%, 700px); margin: auto; padding: clamp(6px, 1vw, 10px); border-radius: 22px; background: linear-gradient(145deg, #d8f0e9, #fff4d8); box-shadow: inset 0 2px 8px rgba(22,64,84,.09); }
.word-grid { display: grid; grid-template-columns: repeat(11, 1fr); gap: clamp(2px, .55vw, 6px); aspect-ratio: 1; user-select: none; -webkit-user-select: none; }
.letter-cell { display: grid; place-items: center; min-width: 0; padding: 0; border: 0; border-radius: clamp(4px, 1vw, 10px); color: var(--deep); background: rgba(255,255,255,.84); font-size: clamp(.72rem, 2.8vw, 1.45rem); font-weight: 900; line-height: 1; cursor: pointer; touch-action: none; transition: background .12s ease, color .12s ease, transform .12s ease; }
.letter-cell.preview { color: white; background: #7f9fbe; transform: scale(.95); }
.letter-cell.found { color: white; background: var(--ocean); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.letter-cell.preview.found { background: var(--coral); }
.gesture-tip { margin: 13px 0 0; color: var(--muted); font-size: .8rem; text-align: center; }

.word-card-heading { display: flex; gap: 12px; align-items: center; padding-bottom: 17px; border-bottom: 1px solid rgba(23,60,93,.1); }
.word-card-heading h2 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 1.45rem; font-weight: 500; }
.mini-compass { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(23,60,93,.12); border-radius: 50%; color: var(--coral); background: var(--sand); font-size: 1.4rem; }
.word-list { display: grid; grid-template-columns: 1fr; gap: 9px; margin: 18px 0; padding: 0; list-style: none; }
.word-list li { display: flex; align-items: center; gap: 10px; min-height: 37px; padding: 8px 10px; border-radius: 11px; background: #f1f7f4; font-size: .87rem; font-weight: 900; letter-spacing: .05em; }
.word-list li::before { content: ""; flex: 0 0 auto; width: 10px; height: 10px; border: 2px solid #9ab0ae; border-radius: 50%; }
.word-list li.found { color: var(--ocean); background: #daf2eb; text-decoration: line-through; text-decoration-thickness: 2px; }
.word-list li.found::before { border-color: var(--ocean); background: var(--ocean); box-shadow: inset 0 0 0 2px #daf2eb; }
.legend { display: flex; gap: 9px; align-items: center; color: var(--muted); font-size: .75rem; line-height: 1.35; }
.legend span { flex: 0 0 auto; width: 19px; height: 8px; border-radius: 99px; background: var(--ocean); }

dialog { color: var(--ink); border: 0; box-shadow: 0 28px 90px rgba(8,40,56,.38); }
dialog::backdrop { background: rgba(10, 42, 57, .64); backdrop-filter: blur(7px); }
.celebration { width: min(520px, calc(100% - 28px)); padding: 30px; border-radius: 30px; text-align: center; background: linear-gradient(180deg, #fffdf7, #effbf7); }
.celebration img { width: 174px; height: 150px; object-fit: contain; border: 3px solid white; border-radius: 28px; background: var(--sand); box-shadow: 0 8px 20px rgba(22,64,84,.13); }
.celebration h2 { margin: 7px 0; font-family: Georgia, serif; font-size: clamp(2rem, 7vw, 3rem); font-weight: 500; }
.celebration p:not(.eyebrow) { color: var(--muted); line-height: 1.5; }
.confetti { color: var(--gold); font-size: 1.75rem; letter-spacing: .2em; }
.celebration-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 20px; }
.celebration-actions .primary-button { grid-column: 1 / -1; }
.primary-button, .secondary-button, .danger-button { min-height: 48px; padding: 11px 16px; border-radius: 14px; cursor: pointer; font-weight: 900; }
.primary-button { border: 0; color: white; background: var(--deep); }
.secondary-button { border: 1px solid rgba(23,60,93,.18); color: var(--deep); background: white; }
.danger-button { border: 0; color: white; background: #a9433b; }
.info-dialog { position: relative; width: min(520px, calc(100% - 28px)); padding: 30px; border-radius: 25px; }
.info-dialog h2 { margin: 0 42px 14px 0; font-family: Georgia, serif; font-size: 2rem; }
.info-dialog li, .info-dialog p { color: var(--muted); line-height: 1.55; }
.close-button { position: absolute; top: 16px; right: 16px; }
.dialog-row { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(22px + var(--safe-bottom)); transform: translate(-50%, 30px); padding: 11px 18px; border-radius: 999px; color: white; background: var(--deep); box-shadow: 0 10px 30px rgba(0,0,0,.22); opacity: 0; pointer-events: none; transition: .25s ease; font-weight: 800; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 760px) {
  .offline-pill { display: none; }
  .app-header { min-height: calc(60px + var(--safe-top)); }
  .brand img { width: 42px; height: 42px; }
  .trail-hero { grid-template-columns: 1fr; min-height: 510px; padding-bottom: 242px; }
  .hero-crew { position: absolute; right: 16px; bottom: 14px; left: 16px; min-height: 218px; }
  .crew-castlebury { top: 26px; width: 140px; height: 158px; }
  .crew-ripple { top: 2px; width: 112px; height: 96px; }
  .crew-dottie { width: 114px; height: 98px; }
  .crew-shelly { width: 112px; height: 101px; }
  .crew-snap { width: 124px; height: 95px; }
  .trail-grid { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .word-card { padding: 18px; }
  .word-list { grid-template-columns: repeat(2, 1fr); }
  .theme-heading { grid-template-columns: 84px 1fr; gap: 15px; }
  .theme-guide-art { width: 84px; height: 84px; border-radius: 22px; }
  .theme-guide-art img { border-radius: 19px; }
  .theme-icon { right: -7px; bottom: -7px; width: 34px; height: 34px; border-radius: 12px; font-size: 1rem; }
  .letter-cell { font-size: clamp(.78rem, 4.2vw, 1.2rem); }
}

@media (max-width: 390px) {
  main { padding-inline: 10px; }
  .word-grid { gap: 2px; }
  .grid-wrap { padding: 5px; }
  .puzzle-card { padding: 10px; }
  .word-card { border-radius: 22px; }
  .word-list li { font-size: .73rem; }
  .trail-hero { min-height: 528px; padding-inline: 21px; }
  .hero-crew { right: 10px; left: 10px; }
  .crew-ripple { left: -4px; }
  .crew-dottie { right: -3px; }
  .crew-shelly { left: -2px; }
  .crew-snap { right: -3px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .app-header { position: relative; }
  main { padding-top: 12px; }
  .theme-heading { margin-bottom: 12px; }
  .theme-heading h1 { font-size: 1.8rem; }
  .game-layout { grid-template-columns: minmax(0, 1.3fr) minmax(220px, .7fr); }
}

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