:root {
  --ink: #27190f;
  --cream: #fff5d7;
  --gold: #f2bd45;
  --orange: #d75031;
  --blue: #2c91c9;
  --shadow: rgba(41, 25, 15, 0.24);
}

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

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

body {
  overflow: hidden;
  background: #c9a86c;
  color: var(--ink);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  user-select: none;
  touch-action: none;
}

body.high-contrast {
  --cream: #ffffff;
  --ink: #000000;
}

#gameWrap {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hud-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}

.pill,
h1,
.prompt,
.touch button,
.modal-card button,
.modal-card a {
  border: 2px solid rgba(39, 25, 15, 0.22);
  background: rgba(255, 245, 215, 0.94);
  box-shadow: 0 5px 0 rgba(39, 25, 15, 0.12), 0 12px 24px var(--shadow);
}

h1 {
  margin: 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: clamp(1rem, 3vw, 1.6rem);
}

.pill {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 800;
  text-decoration: none;
  color: var(--ink);
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
}

.pill:focus-visible,
.touch button:focus-visible,
.primary:focus-visible,
.secondary:focus-visible,
.sabbath-card:focus-visible,
.sabbath-slot:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.journey-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(39, 25, 15, 0.15);
  overflow: hidden;
  pointer-events: none;
}

#journeyBar {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--orange));
  transition: width 0.4s ease;
}

.prompt {
  position: fixed;
  left: 50%;
  top: calc(118px + env(safe-area-inset-top));
  z-index: 5;
  width: min(560px, calc(100vw - 24px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  line-height: 1.3;
}

#caption {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  z-index: 7;
  max-width: 90vw;
  text-align: center;
}

.touch {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  gap: 10px;
  pointer-events: none;
}

.touch button {
  pointer-events: auto;
  min-height: 58px;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.touch .dash {
  background: linear-gradient(135deg, #fff6d9, #ffd35c);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(48, 32, 18, 0.45);
}

.modal[hidden],
#sabbathMount[hidden],
#journalPanel[hidden],
#parentContent[hidden],
.resume-prompt[hidden] {
  display: none !important;
}

.modal-card {
  width: min(620px, 100%);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
}

.modal-card p {
  margin: 0 auto 16px;
  max-width: 48ch;
  line-height: 1.45;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.primary,
.secondary {
  min-height: 48px;
  min-width: 44px;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  background: var(--orange);
  color: #fff;
  border: 2px solid #8e2f1c;
}

.secondary {
  background: var(--cream);
  color: var(--ink);
}

#sabbathMount {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(232, 224, 200, 0.92);
  overflow-y: auto;
}

.sabbath-panel {
  max-width: 640px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 0 rgba(39, 25, 15, 0.15);
}

.sabbath-header h2 {
  margin: 0 0 8px;
}

.sabbath-lead {
  margin: 0 0 12px;
  line-height: 1.4;
}

.sabbath-progress {
  margin-bottom: 14px;
}

.sabbath-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.sabbath-phase-label {
  font-weight: 800;
}

.sabbath-timer {
  opacity: 0.8;
  font-size: 0.82rem;
}

.sabbath-bar,
.sabbath-phase-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(39, 25, 15, 0.12);
  overflow: hidden;
}

.sabbath-bar-fill,
.sabbath-phase-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), #6ab8e0);
  transition: width 0.5s ease;
}

.sabbath-phase-bar {
  height: 4px;
  margin-top: 6px;
}

.sabbath-phase-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 8px 0 4px;
}

.sabbath-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(39, 25, 15, 0.2);
}

.sabbath-dot.active {
  background: var(--gold);
}

.sabbath-dot.done {
  background: #6a9e5a;
}

.sabbath-timeline,
.sabbath-pool {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.sabbath-timeline {
  grid-template-columns: 1fr;
  position: relative;
  padding-left: 28px;
}

.sabbath-timeline::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--gold), var(--blue));
}

.sabbath-pool {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.memory-card:focus-visible,
.camp-item:focus-visible,
.camp-cell:focus-visible,
.gratitude-stone:focus-visible,
.parent-toggle:focus-visible,
.sabbath-skip:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.sabbath-slot,
.sabbath-card,
.memory-card,
.camp-item,
.camp-cell,
.gratitude-stone {
  min-height: 48px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.sabbath-slot {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: start;
}

.sabbath-slot-num {
  grid-row: span 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
}

.sabbath-card.selected,
.camp-item.selected {
  border-color: var(--blue);
  background: #e8f4fc;
}

.sabbath-slot.filled {
  background: #e8f8e0;
}

.sabbath-hint {
  margin: 0 0 10px;
  font-weight: 700;
}

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

.memory-card {
  min-height: 72px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.memory-card.face-up {
  background: #fff8e0;
}

.memory-card.matched {
  background: #dff5d5;
  border-color: #4a8a40;
  cursor: default;
}

.memory-back {
  font-size: 1.4rem;
  font-weight: 800;
  opacity: 0.5;
}

.memory-emoji {
  font-size: 1.2rem;
}

.sabbath-camp-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.camp-item.placed {
  opacity: 0.55;
  cursor: default;
}

.camp-item strong,
.sabbath-card strong {
  display: block;
}

.camp-item span,
.sabbath-card span {
  font-size: 0.82rem;
  opacity: 0.85;
}

.sabbath-camp-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.camp-cell {
  min-height: 52px;
  font-size: 0.75rem;
  text-align: center;
  padding: 6px;
}

.camp-cell.occupied {
  background: #e8f8e0;
}

.sabbath-gratitude-stones {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 16px 0;
}

.gratitude-stone {
  width: 64px;
  height: 64px;
  min-height: 64px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #d8cfc0, #b8a890);
  padding: 0;
}

.gratitude-stone.tapped {
  background: linear-gradient(145deg, #c8e8b8, #98c878);
  border-color: #4a8a40;
}

.stone-glyph {
  font-size: 1.1rem;
  line-height: 1;
}

.stone-num {
  font-size: 0.7rem;
  font-weight: 800;
}

.sabbath-gratitude-msg {
  text-align: center;
  font-style: italic;
  min-height: 2.5em;
  margin: 0;
}

.sabbath-footer {
  margin-top: 16px;
  border-top: 1px solid rgba(39, 25, 15, 0.15);
  padding-top: 12px;
}

.sabbath-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}

.sabbath-skip {
  min-height: 44px;
}

.sabbath-ref {
  font-size: 0.75rem;
  opacity: 0.7;
  text-align: center;
  margin: 0;
}

.parent-panel {
  position: fixed;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(78px, calc(68px + env(safe-area-inset-bottom)));
  z-index: 8;
  max-width: min(320px, calc(100vw - 24px));
  pointer-events: auto;
}

.parent-toggle {
  min-height: 44px;
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 245, 215, 0.96);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  padding: 8px 12px;
  text-align: left;
}

.parent-toggle:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.parent-content {
  margin-top: 8px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 12px;
  max-height: 40vh;
  overflow-y: auto;
}

.parent-content h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.parent-list {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.parent-ccc,
.parent-note {
  font-size: 0.82rem;
  line-height: 1.4;
  margin: 0 0 10px;
}

.resume-prompt {
  margin-bottom: 12px;
  padding: 12px;
  border: 2px dashed rgba(39, 25, 15, 0.25);
  border-radius: 8px;
}

.chapter-replay-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 800;
}

.chapter-replay-select {
  min-height: 44px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 12px;
  font: inherit;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px;
}

.intro-card {
  max-width: 420px;
}

.intro-icon {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: 8px;
}

.intro-hint {
  font-size: 0.92rem;
  opacity: 0.85;
  margin-bottom: 14px !important;
}

.micro-goal-pill {
  font-size: 0.88rem;
  max-width: 100%;
  line-height: 1.25;
}

.micro-progress {
  font-weight: 900;
  color: var(--orange);
}

.end-themes {
  text-align: left;
  max-width: 36ch;
  margin: 0 auto 14px;
  padding-left: 1.2rem;
  line-height: 1.45;
  font-size: 0.95rem;
}

.qa-badge {
  position: fixed;
  bottom: 8px;
  right: 8px;
  z-index: 99;
  background: #c00;
  color: #fff;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
  pointer-events: none;
}

#journalPanel {
  position: fixed;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 8;
  width: min(280px, 90vw);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 14px;
  pointer-events: auto;
}

@media (max-width: 760px) {
  .prompt {
    top: calc(168px + env(safe-area-inset-top));
    font-size: 0.9rem;
  }
  .pill {
    font-size: 0.82rem;
    padding: 6px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #journeyBar {
    transition: none;
  }
}