:root {
  --ink: #17352f;
  --muted: #5f716d;
  --green: #154f43;
  --green-2: #237162;
  --mint: #dff3eb;
  --cream: #fffaf0;
  --paper: #ffffff;
  --gold: #f5c84b;
  --gold-soft: #fff1b9;
  --coral: #e85e68;
  --coral-soft: #ffe1df;
  --blue: #4a8fc5;
  --blue-soft: #e0f0fb;
  --purple: #7b67a8;
  --shadow: 0 16px 40px rgba(20, 67, 56, .13);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--cream); color: var(--ink); font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 8% 2%, #fff1bd 0 8%, transparent 27%), radial-gradient(circle at 93% 15%, #dff3eb 0 12%, transparent 34%), var(--cream); }
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 4px solid #90d6f5; outline-offset: 3px; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 999; padding: 12px 18px; border-radius: 12px; background: #fff; color: var(--ink); }
.skip-link:focus { top: 12px; }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px clamp(16px, 4vw, 48px); background: rgba(255, 250, 240, .93); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(21, 79, 67, .1); }
.brand { display: flex; align-items: center; gap: 11px; border: 0; padding: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; color: #684e00; background: var(--gold); font-size: 26px; box-shadow: 0 7px 0 #ddb131; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: clamp(17px, 3vw, 22px); line-height: 1; }
.brand small { margin-top: 5px; color: var(--muted); font-weight: 700; }
.top-actions { display: flex; gap: 10px; }
.storage-button { min-height: 48px; display: inline-flex; align-items: center; gap: 8px; padding: 10px 15px; border: 2px solid #bdd7cf; border-radius: 999px; background: #fff; color: var(--green); font-weight: 900; cursor: pointer; }
.storage-dot { width: 12px; height: 12px; flex: none; border-radius: 50%; background: #a7b2ae; box-shadow: 0 0 0 4px #edf1f0; }
.storage-dot.online { background: #2d9b6f; box-shadow: 0 0 0 4px #dff3eb; }
.storage-dot.warning { background: #d39700; box-shadow: 0 0 0 4px #fff1b9; }
.storage-dot.error { background: #d14957; box-shadow: 0 0 0 4px #ffe1df; }
.pill-button, .round-button, .primary-button, .secondary-button, .choice-button, .icon-action { min-height: 48px; border: 0; cursor: pointer; font-weight: 900; }
.pill-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--green); color: #fff; box-shadow: 0 5px 0 #0d382f; }
.pill-button:active, .primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #0d382f; }
.round-button { width: 48px; border-radius: 50%; color: var(--ink); background: #fff; box-shadow: 0 5px 15px rgba(20, 67, 56, .12); font-size: 26px; }

#app { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: clamp(20px, 4vw, 44px) 0 calc(118px + var(--safe-bottom)); }
.screen { animation: liftIn .32s ease both; }
@keyframes liftIn { from { opacity: 0; transform: translateY(10px); } }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--green-2); font-size: 14px; font-weight: 950; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 820px; margin-bottom: 14px; font-size: clamp(36px, 7vw, 76px); line-height: .98; letter-spacing: -.04em; }
h2 { font-size: clamp(26px, 4vw, 40px); line-height: 1.05; }
h3 { font-size: 20px; }
.lead { max-width: 720px; color: #445e57; font-size: clamp(18px, 2.5vw, 23px); line-height: 1.48; }
.hero { position: relative; overflow: hidden; display: grid; grid-template-columns: 1.05fr .95fr; align-items: center; min-height: 475px; padding: clamp(26px, 5vw, 62px); border-radius: 36px; background: linear-gradient(145deg, #fdf1ba, #fff7dc 43%, #dcefe8); box-shadow: var(--shadow); }
.hero::before { content: ""; position: absolute; inset: 16px; border: 2px dashed rgba(21,79,67,.16); border-radius: 27px; pointer-events: none; }
.hero-copy, .hero-art { position: relative; z-index: 1; }
.hero-art img { width: 100%; max-height: 390px; object-fit: contain; filter: drop-shadow(0 16px 20px rgba(21,79,67,.12)); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.primary-button, .secondary-button { padding: 14px 22px; border-radius: 17px; }
.primary-button { color: #fff; background: var(--green); box-shadow: 0 6px 0 #0d382f; }
.secondary-button { color: var(--green); background: #fff; border: 2px solid var(--green); }
.jesus-ribbon { display: inline-flex; align-items: center; gap: 9px; padding: 9px 13px; border-radius: 999px; background: #fff; color: var(--green); font-weight: 950; box-shadow: 0 5px 18px rgba(21,79,67,.1); }
.jesus-ribbon span { color: #c99100; }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 0 0 22px; }
.section-head h1 { margin-bottom: 0; font-size: clamp(34px, 6vw, 60px); }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mission-grid { grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); }
.card { position: relative; padding: 22px; border: 1px solid rgba(21,79,67,.1); border-radius: var(--radius); background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.card p:last-child { margin-bottom: 0; }
.mission-card { overflow: hidden; min-height: 250px; display: flex; flex-direction: column; }
.mission-card::after { content: attr(data-number); position: absolute; right: -4px; bottom: -34px; color: rgba(21,79,67,.06); font-size: 142px; font-weight: 950; line-height: 1; }
.mission-card .mission-icon { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 20px; border-radius: 21px; background: var(--mission-soft); font-size: 34px; }
.mission-card h3 { margin-bottom: 7px; font-size: 25px; }
.mission-card .virtue { color: var(--mission); font-weight: 950; }
.mission-card .card-actions { display: flex; align-items: center; gap: 9px; margin-top: auto; padding-top: 18px; position: relative; z-index: 1; }
.status-chip { display: inline-flex; align-items: center; min-height: 32px; padding: 5px 10px; border-radius: 999px; background: #edf4f1; color: var(--green); font-size: 13px; font-weight: 900; }
.status-chip.done { background: var(--mint); }
.icon-action { display: inline-grid; place-items: center; width: 48px; border-radius: 50%; background: var(--blue-soft); color: #18557e; }
.icon-action.playing { animation: pulse 1s infinite; background: var(--gold-soft); }
@keyframes pulse { 50% { transform: scale(1.08); } }

.mission-stage { display: grid; grid-template-columns: 300px 1fr; gap: 22px; align-items: start; }
.mission-map { position: sticky; top: 96px; }
.mission-map .map-star { display: grid; place-items: center; width: 110px; height: 110px; margin: -4px auto 18px; clip-path: polygon(50% 0,61% 34%,98% 35%,68% 57%,79% 94%,50% 72%,21% 94%,32% 57%,2% 35%,39% 34%); background: var(--gold); color: #6d5200; font-size: 34px; font-weight: 950; }
.mission-map ol { list-style: none; margin: 0; padding: 0; }
.mission-map li { display: flex; gap: 10px; align-items: center; margin: 8px 0; color: var(--muted); font-weight: 800; }
.mission-map li::before { content: ""; width: 14px; height: 14px; flex: none; border-radius: 50%; background: #d9e5e1; }
.mission-map li.active { color: var(--ink); }
.mission-map li.active::before { background: var(--coral); box-shadow: 0 0 0 5px var(--coral-soft); }
.step-card { padding: clamp(22px, 4vw, 36px); }
.step-top { display: flex; align-items: start; justify-content: space-between; gap: 14px; }
.mode-tag { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 7px 11px; border-radius: 10px; font-size: 13px; font-weight: 950; text-transform: uppercase; letter-spacing: .05em; }
.mode-tag.paper { background: var(--gold-soft); color: #705700; }
.mode-tag.tablet { background: var(--blue-soft); color: #18557e; }
.story-bubble { position: relative; margin: 22px 0; padding: 22px 22px 22px 76px; border-radius: 22px; background: #f2faf7; color: #274f46; font-size: 18px; line-height: 1.5; }
.story-bubble::before { content: attr(data-speaker); position: absolute; left: 17px; top: 17px; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: #6c5100; font-size: 12px; font-weight: 950; text-align: center; }
.step-instruction { font-size: clamp(20px, 3vw, 26px); line-height: 1.42; }
.step-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.timer { display: grid; place-items: center; width: 160px; height: 160px; margin: 22px auto; border: 13px solid var(--mint); border-top-color: var(--green); border-radius: 50%; color: var(--green); font-size: 38px; font-weight: 950; }

.profile-switch { display: inline-flex; gap: 7px; padding: 6px; border-radius: 18px; background: #e8f1ee; }
.profile-switch button { min-height: 45px; padding: 9px 15px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); font-weight: 950; cursor: pointer; }
.profile-switch button.active { background: #fff; color: var(--green); box-shadow: 0 6px 15px rgba(21,79,67,.12); }
.letter-desk { display: grid; grid-template-columns: 1.1fr .9fr; gap: 20px; }
.letter-paper { min-height: 520px; padding: clamp(24px, 4vw, 42px); background: repeating-linear-gradient(#fff 0 39px, #d8e7e1 40px); }
.letter-paper::before { content: ""; position: absolute; left: 42px; top: 0; bottom: 0; width: 2px; background: #ffd5d5; }
.letter-paper > * { position: relative; z-index: 1; }
.letter-paper textarea { width: 100%; min-height: 330px; resize: vertical; border: 0; padding: 8px 12px 8px 20px; background: transparent; color: var(--ink); font-size: 22px; line-height: 40px; }
.big-record { display: grid; place-items: center; width: 150px; height: 150px; margin: 26px auto 16px; border: 8px solid #fff; border-radius: 50%; background: var(--coral); color: #fff; box-shadow: 0 0 0 8px var(--coral-soft), 0 18px 35px rgba(182,52,65,.22); font-size: 50px; cursor: pointer; }
.big-record.recording { animation: pulse 1s infinite; }
.center { text-align: center; }
.tip-list { margin: 0; padding: 0; list-style: none; }
.tip-list li { display: flex; gap: 12px; margin: 13px 0; line-height: 1.4; }
.tip-list li::before { content: "★"; color: #d49f00; }

.week-picker { display: flex; gap: 8px; margin: 0 0 18px; overflow-x: auto; padding: 4px 2px 10px; }
.week-picker button { flex: 0 0 auto; min-width: 104px; min-height: 52px; border: 0; border-radius: 16px; background: #e7f0ed; color: var(--green); font-weight: 950; cursor: pointer; }
.week-picker button.active { background: var(--green); color: #fff; box-shadow: 0 6px 0 #0d382f; }
.star-table-wrap { overflow-x: auto; border-radius: 22px; box-shadow: var(--shadow); }
.star-table { width: 100%; min-width: 860px; border-collapse: collapse; background: #fff; }
.star-table th, .star-table td { padding: 13px 9px; border: 1px solid #e3ece9; text-align: center; }
.star-table thead th { background: var(--green); color: #fff; }
.star-table tbody th { width: 280px; text-align: left; background: #f4faf7; }
.star-toggle { width: 48px; height: 48px; border: 0; border-radius: 14px; background: #f0f3f2; color: #c5cfcc; font-size: 28px; cursor: pointer; }
.star-toggle.on { background: var(--gold-soft); color: #c28d00; transform: rotate(-7deg); }
.score-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding: 18px 22px; border-radius: 20px; background: linear-gradient(90deg, var(--gold-soft), #fff9dc); }
.score-banner strong { font-size: 26px; }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.memory-card { overflow: hidden; padding: 0; }
.memory-card img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #e8f1ee; }
.memory-card audio { width: calc(100% - 28px); margin: 26px 14px 10px; }
.memory-meta { padding: 16px; }
.memory-actions { display: flex; gap: 8px; margin-top: 12px; }
.memory-actions a, .memory-actions button { flex: 1; min-height: 42px; display: grid; place-items: center; border: 0; border-radius: 11px; text-decoration: none; background: #e8f1ee; color: var(--green); font-weight: 900; cursor: pointer; }
.empty-state { grid-column: 1/-1; padding: 52px 24px; text-align: center; }
.empty-state .empty-icon { display: grid; place-items: center; width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 30px; background: var(--mint); font-size: 44px; }

.bottom-note, .note-card { padding: 17px 19px; border-radius: 18px; line-height: 1.45; }
.bottom-note { margin-top: 22px; background: #edf6f2; color: #31584f; }
.note-card { background: var(--gold-soft); color: #5d4b09; }
.warning-card { background: var(--coral-soft); color: #71333a; }

.media-dialog, .help-dialog, .storage-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100vh - 30px); border: 0; padding: 0; border-radius: 28px; color: var(--ink); background: #fff; box-shadow: 0 35px 90px rgba(10,46,38,.35); }
dialog::backdrop { background: rgba(8,39,32,.68); backdrop-filter: blur(5px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 18px 22px; background: #fff; border-bottom: 1px solid #e6eeeb; }
.dialog-head h2 { margin: 0; font-size: 25px; }
#mediaDialogBody { padding: 22px; }
.camera-preview { width: 100%; max-height: 55vh; border-radius: 20px; background: #11211e; object-fit: cover; }
.capture-row { display: flex; justify-content: center; gap: 12px; margin-top: 18px; }
.capture-button { width: 78px; height: 78px; border: 7px solid #fff; outline: 4px solid var(--coral); border-radius: 50%; background: var(--coral); cursor: pointer; }
.recorder-panel { padding: 35px 15px; text-align: center; }
.record-time { margin: 14px 0; font-size: 42px; font-weight: 950; font-variant-numeric: tabular-nums; }
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 22px; }
.help-grid article { padding: 18px; border-radius: 20px; background: #f4f9f7; text-align: center; }
.help-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 12px; border-radius: 18px; font-size: 26px; font-weight: 950; }
.help-icon.tablet { background: var(--blue-soft); color: #17587f; }
.help-icon.paper { background: var(--gold-soft); color: #735800; }
.help-icon.together { background: var(--coral-soft); color: #8d3540; }
.help-dialog .note-card { margin: 0 22px 22px; }
.storage-dialog-body { padding: 22px; }
.storage-status-card { display: flex; align-items: flex-start; gap: 14px; padding: 18px; border-radius: 18px; background: #f4f9f7; }
.storage-status-card .storage-dot { margin-top: 5px; }
.storage-status-card p { margin: 5px 0 0; color: var(--muted); line-height: 1.4; }
#storageLoginForm { margin-top: 20px; }
.storage-login-row { display: flex; gap: 10px; margin-top: 8px; }
.storage-login-row input { min-width: 0; flex: 1; min-height: 52px; padding: 10px 14px; border: 2px solid #bdd7cf; border-radius: 15px; color: var(--ink); background: #fff; }
.field-help { margin: 9px 0 0; color: var(--muted); font-size: 14px; }
.storage-auth-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.toast { position: fixed; left: 50%; bottom: calc(102px + var(--safe-bottom)); z-index: 100; max-width: calc(100% - 32px); transform: translate(-50%, 30px); padding: 13px 18px; border-radius: 999px; background: #17352f; color: #fff; font-weight: 850; opacity: 0; pointer-events: none; transition: .25s ease; box-shadow: 0 12px 30px rgba(0,0,0,.25); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.bottom-nav { position: fixed; left: 50%; bottom: calc(14px + var(--safe-bottom)); z-index: 30; transform: translateX(-50%); width: min(760px, calc(100% - 24px)); display: flex; justify-content: space-around; padding: 8px; border: 1px solid rgba(255,255,255,.7); border-radius: 24px; background: rgba(21,79,67,.96); box-shadow: 0 18px 45px rgba(11,49,41,.28); backdrop-filter: blur(12px); }
.bottom-nav button { min-width: 92px; min-height: 60px; display: grid; gap: 1px; place-items: center; border: 0; border-radius: 17px; background: transparent; color: #dfeee9; font-weight: 850; cursor: pointer; }
.bottom-nav button span:first-child { font-size: 23px; }
.bottom-nav button.active { background: #fff; color: var(--green); }

@media (max-width: 850px) {
  .hero, .letter-desk, .mission-stage { grid-template-columns: 1fr; }
  .hero { padding-bottom: 22px; }
  .hero-art { order: -1; }
  .hero-art img { max-height: 265px; }
  .mission-map { position: static; }
  .mission-map ol { display: flex; overflow-x: auto; gap: 10px; padding-bottom: 5px; }
  .mission-map li { flex: 0 0 auto; padding: 8px 11px; border-radius: 12px; background: #f1f6f4; }
  .mission-map .map-star { width: 78px; height: 78px; margin: 0 auto 12px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .help-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .sound-page span:last-child, .brand small, #storageLabel { display: none; }
  .storage-button { width: 48px; padding: 0; justify-content: center; }
  .sound-page { width: 48px; padding: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .section-head { display: block; }
  .section-head .profile-switch { margin-top: 14px; }
  .hero { border-radius: 26px; }
  .letter-paper::before { left: 25px; }
  .bottom-nav { bottom: calc(7px + var(--safe-bottom)); border-radius: 20px; }
  .bottom-nav button { min-width: 0; min-height: 56px; padding: 5px 8px; font-size: 11px; }
  .bottom-nav button span:first-child { font-size: 20px; }
  .storage-login-row { align-items: stretch; flex-direction: column; }
}

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

@media print {
  .topbar, .bottom-nav, .hero-actions, .icon-action, .pill-button, .primary-button, .secondary-button { display: none !important; }
  body { background: #fff; }
  #app { width: 100%; padding: 0; }
  .card, .hero { box-shadow: none; break-inside: avoid; }
}
