/* Drawing the Hours — Meadow Paper Aesthetic Styles */

/* Default mode uses the selected chapter palette. Light mode keeps the rules below. */
html[data-color-mode="default"] body { background-image: none; }
html[data-color-mode="default"] .brand h1 { color: var(--text-dark); }
html[data-color-mode="default"] button:hover { background: var(--panel-bg); border-color: var(--text-muted); }
html[data-color-mode="default"] button:focus-visible { outline-color: var(--text-dark); }
html[data-color-mode="default"] #btn-visit,
html[data-color-mode="default"] #btn-gesture-mode,
html[data-color-mode="default"] .close-btn,
html[data-color-mode="default"] .modal-close-btn,
html[data-color-mode="default"] .visit-item {
  background: var(--panel-bg); color: var(--text-dark); border-color: var(--border-paper);
}
html[data-color-mode="default"] .visit-item:hover { border-color: var(--text-muted); }
html[data-color-mode="default"][data-hour="dusk"],
html[data-color-mode="default"][data-hour="midnight"] { color-scheme: dark; }

:root {
  --bg-cream: #f4efe2;
  --panel-bg: #fdfbf7;
  --border-paper: #d8cdb8;
  --text-dark: #3a3225;
  --text-muted: #786c5a;
  --accent-terracotta: #c85a32;
  --accent-blush: #b65e79;
  --accent-plum: #5a3a66;
  --accent-green: #486940;
  --shadow-soft: 0 8px 24px rgba(60, 50, 35, 0.08);
  --shadow-card: 0 4px 14px rgba(45, 38, 28, 0.07);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-cream);
  color: var(--text-dark);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

header {
  width: 100%;
  max-width: 1000px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px 12px;
}

.brand h1 {
  font-family: Mali, cursive;
  font-size: 1.8rem;
  font-weight: 700;
  color: #85485e;
  letter-spacing: -0.045em;
}

.brand .sub {
  font-family: Mali, sans-serif;
  font-style: normal;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.controls {
  display: flex;
  gap: 8px;
}

button {
  background: var(--panel-bg);
  border: 1.5px solid var(--border-paper);
  border-radius: 12px 9px 13px 8px;
  color: var(--text-dark);
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: Mali, sans-serif;
  min-height: 42px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(50, 40, 30, 0.05);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover {
  background: #ffffff;
  border-color: #b5a489;
  transform: translateY(-1px);
}

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

button:focus-visible {
  outline: 3px solid #985477;
  outline-offset: 3px;
}

body {
  background-image: radial-gradient(ellipse at 10% 0%, #f6e1e6 0, transparent 55%),
    radial-gradient(ellipse at 95% 100%, #e1e8d5 0, transparent 55%);
}

#btn-visit, .close-btn, .modal-close-btn {
  background: #f4dce3;
  border-color: #d3aaba;
  color: #713e52;
}

#btn-gesture-mode.mode-trace {
  background: #e2eef5;
  border-color: #79a6be;
  color: #265069;
}

#btn-gesture-mode.mode-enclose {
  background: #fae8ee;
  border-color: #c98ea1;
  color: #713e52;
}

#btn-gesture-mode:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.recipe-card h2, .recipe-info h3, .visit-section-title {
  font-family: Mali, sans-serif;
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:hover, button:active { transform: none; }
}

.stage-wrapper {
  position: relative;
  width: 100%;
  max-width: 1000px;
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-soft);
  border: 2px solid var(--border-paper);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

canvas#game-canvas {
  width: 100%;
  height: 640px;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

footer {
  width: 100%;
  max-width: 1000px;
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0 8px;
}

.recipe-modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 30, 22, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.recipe-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.recipe-card {
  position: relative;
  background: var(--panel-bg);
  border: 2px solid var(--border-paper);
  border-radius: 14px;
  width: 90%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 16px 36px rgba(40, 30, 20, 0.2);
}

.recipe-card h2 {
  font-family: Georgia, serif;
  font-size: 1.4rem;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.recipe-card .field-intro {
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-paper);
  padding-bottom: 10px;
}

.recipe-entry {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border-paper);
}

.recipe-entry:last-child {
  border-bottom: none;
}

.entry-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  height: fit-content;
  white-space: nowrap;
}

.badge-single {
  background: #f5e4db;
  color: #92401f;
}

.badge-double {
  background: #ede2f2;
  color: #582e6c;
}

.recipe-info h3 {
  font-size: 0.98rem;
  font-weight: 600;
  margin-bottom: 3px;
}

.recipe-info p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.close-btn {
  margin-top: 14px;
  width: 100%;
  justify-content: center;
}

.modal-close-btn {
  position: sticky;
  top: 0;
  float: right;
  z-index: 25;
  width: 36px;
  height: 36px;
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  margin: -4px -4px 0 8px;
  border-radius: 50%;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(50, 40, 30, 0.08);
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  background: #ffffff;
  border-color: #b5a489;
  transform: scale(1.06);
}

.modal-close-btn:active {
  transform: scale(0.94);
}

.modal-close-btn:focus-visible {
  outline: 3px solid #985477;
  outline-offset: 2px;
}

.shell-card .modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  margin: 0;
}

/* =========================================================
   Visit / Chapter Selection Modal Styles
   ========================================================= */

.visit-card {
  max-width: 580px;
}

.visit-section {
  margin-bottom: 12px;
}

.visit-section-title {
  font-family: Georgia, serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-paper);
  padding-bottom: 4px;
}

.visit-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.visit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--border-paper);
  border-radius: 8px;
  background: #fbf9f4;
  cursor: pointer;
  transition: all 0.15s ease;
  gap: 10px;
  text-align: left;
}

.visit-item:hover:not(.locked) {
  background: #ffffff;
  border-color: #b5a489;
  transform: translateX(2px);
}

.visit-item.active {
  border-color: var(--accent-green);
  background: #f1f7ed;
}

.visit-item.locked {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f5f2eb;
}

.visit-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.visit-item-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-dark);
}

.visit-item-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.visit-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.visit-item-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.visit-item-badge.completed {
  background: #e1f2dc;
  color: #2e6628;
}

.visit-item-badge.current {
  background: #fcecd7;
  color: #8c4712;
}

.visit-item-badge.locked {
  background: #ece8e1;
  color: #797166;
}

@media (max-width: 600px) {
  .recipe-card {
    width: 95%;
    padding: 16px;
    max-height: 88vh;
  }

  .recipe-card h2 {
    font-size: 1.2rem;
  }

  .recipe-card .field-intro {
    font-size: 0.82rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
  }

  .recipe-entry {
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }

  .recipe-info h3 {
    font-size: 0.92rem;
  }

  .recipe-info p {
    font-size: 0.78rem;
    line-height: 1.3;
  }
}


/* The stage is the application viewport. Menus stay inside it. */
html, body { width: 100%; height: 100%; overflow: hidden; }
body { padding: 0; min-height: 0; display: block; }
body .stage-wrapper {
  position: fixed; inset: 0; width: 100%; height: 100dvh;
  max-width: none; max-height: none; min-height: 0;
  border: 0; border-radius: 0; box-shadow: none;
}
body .stage-wrapper canvas#game-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; outline: none;
}
.stage-pause {
  position: absolute; right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom)); z-index: 10;
  min-width: 68px; min-height: 44px; opacity: 0.9;
}
[hidden] { display: none !important; }
.stage-wrapper > .recipe-modal {
  position: absolute; transition: none;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.stage-wrapper > .recipe-modal:not(.active) { visibility: hidden; }
.stage-wrapper .recipe-card { max-height: 100%; overscroll-behavior: contain; }
.shell-card { max-width: 420px; text-align: center; }
.shell-card h1 { font: 600 clamp(26px, 5vw, 40px) Mali, sans-serif; margin-bottom: 16px; }
.shell-card p { color: var(--text-muted); font-size: .85rem; line-height: 1.5; margin: 14px 0; }
.menu-buttons { display: grid; gap: 8px; margin: 16px 0; }
.menu-buttons button, #btn-begin { justify-content: center; min-height: 44px; width: 100%; }
@media (max-width: 680px) and (orientation: portrait) {
  body { height: 100dvh; min-height: 0; }
  body:not(.is-horizontal) .stage-wrapper {
    width: 100%; max-width: none; height: 100dvh; max-height: none; min-height: 0; border-radius: 0;
  }
}

#title-screen { background: var(--bg-cream); backdrop-filter: none; }
#title-screen .recipe-card { border: 0; box-shadow: none; background: transparent; }

/* Fit one fixed logical field inside the viewport; never stretch its axes. */
body .stage-wrapper canvas#game-canvas {
  inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%);
}
