@import url('https://fonts.googleapis.com/css2?family=Yuji+Syuku&display=swap');

:root {
  --color-ink: #10160f;              /* dark UI chrome: scanner viewfinder, modal scrim */
  --color-washi: #ffffff;            /* page background — completely white */
  --color-paper: #ffffff;            /* card surface — completely white */
  --color-amber: #c99a52;            /* primary accent (replaces corporate blue) */
  --color-amber-deep: #a97e3d;       /* accent hover/active */
  --color-amber-soft: rgba(201, 154, 82, 0.16); /* accent tint background (badges, chips) */
  --color-ink-text: #1d3f21;         /* the one text/button-fill/border/divider color used everywhere */
  --color-text-muted: #1d3f21;       /* same ink — no separate lighter/gray variant */
  --color-border-soft: #1d3f21;      /* same ink — card/input borders */

  /* --font-display: titles/headings (Yu Gothic). --font-body: body copy (Yu Mincho).
     --font-hand: journal's accumulated-text background (untouched, hand-drawn). */
  --font-display: "Yu Gothic", "游ゴシック体", "YuGothic", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-hand: "Yuji Syuku", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --font-body: "Yu Mincho", "游明朝", "YuMincho", "Hiragino Mincho ProN", serif;

  --ease-breath: cubic-bezier(0.45, 0, 0.2, 1);
  --dur-slow: 900ms;
  --dur-med: 450ms;
  --dur-fast: 200ms;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;

  /* Minimum comfortable tap target for icon/pill buttons */
  --tap-target-min: 44px;

  /* Safe-area insets (require viewport-fit=cover on the page's viewport meta tag) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

* {
  box-sizing: border-box;
}

html {
  /* Scales every rem-based font-size site-wide (16px -> 18px base) for
     better mobile readability, without touching each declaration. */
  font-size: 112.5%;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--color-washi);
  color: var(--color-ink-text);
  text-align: center;
  padding: 20px;
}

.card {
  position: relative;
  background: var(--color-paper);
  padding: 30px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(16, 22, 15, 0.08);
  border: 1.5px solid var(--color-border-soft);
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Full-bleed, fixed-height sizing utility — used by journal, which fills the screen
   edge to edge and manages its own internal scroll region (.journal-bg-scroll). */
.card-fill {
  height: 100dvh;
  overflow: hidden;
}

/* Full-bleed, fixed-height utility for simpler linear-content pages (home, audioguide) —
   fills the screen exactly like .card-fill, but scrolls its own content vertically if it
   overflows, since these pages don't have their own internal scroll region. */
.card-fill-scroll {
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* "safe" keeps short content centered but falls back to top-alignment instead of
     clipping the start of the content when it grows taller than the screen and scrolls. */
  justify-content: safe center;
  /* Scrolling stays fully functional (touch/wheel/keyboard) — only the visible
     scrollbar track/thumb is hidden, matching the treatment already used for
     journal's own scrollable archive text area. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.card-fill-scroll::-webkit-scrollbar {
  display: none;
}

/* index.html only: #card additionally pins a static "End Journey" button to
   the bottom of the card, below .error-view's own (still centered) content -
   the button is a sibling of .error-view, hidden via display:none except in
   the theme-word view. .error-view takes the remaining space above it and
   centers its content within that space, same as it always has. */
#card.card-fill-scroll {
  justify-content: flex-start;
}

#card .error-view {
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* .error-view's default align-items: center sizes #content to its own
   shrink-to-fit content width (then centers that box) rather than
   stretching it - so anything inside relying on width: 100% (the section
   divider, the View Journals button) could end up narrower than the card,
   or on some content/viewport combinations collapse enough to be barely
   visible. Force it to actually span the full width instead. */
#card #content {
  width: 100%;
}

/* Entrance animation — a plain fade, no movement, used on the main card across pages */
.enter-fade {
  animation: enterFade var(--dur-slow) var(--ease-breath) both;
}

@keyframes enterFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Native cross-document fade between full page navigations (Chrome/Edge; other browsers
   simply ignore this and navigate instantly, so it's a safe progressive enhancement). */
@view-transition {
  navigation: auto;
}

/* Slow ambient pulse — applied to the connection dot and ambient glow elements */
.breathe {
  animation: breathe 5s var(--ease-breath) infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.12); }
}

/* Soft radial glow, like distant candlelight, placed behind a card */
.ambient-glow {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  width: 70vw;
  height: 70vw;
  max-width: 480px;
  max-height: 480px;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(201, 154, 82, 0.22) 0%, rgba(201, 154, 82, 0.08) 45%, rgba(201, 154, 82, 0) 72%);
  animation: breathe 6s var(--ease-breath) infinite;
}

/* User Badge Header */
.user-badge {
  align-self: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-amber-deep);
  background: var(--color-amber-soft);
  padding: 4px 12px;
  border-radius: 12px;
  margin-bottom: 10px;
  display: none;
}

h1 {
  margin: 0 0 6px 0;
  font-size: 1.3rem;
  font-family: var(--font-display);
}

p, .description {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0 0 12px 0;
}

audio {
  width: 100%;
  margin-top: 10px;
  margin-bottom: 20px;
}

.journal-btn {
  display: none;
  width: 100%;
  box-sizing: border-box;
  min-height: var(--tap-target-min);
  padding: 12px 0;
  background: var(--color-ink-text);
  color: var(--color-washi);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: calc(var(--tap-target-min) - 24px);
  border-radius: 6px;
  transition: background var(--dur-fast), transform 0.1s;
  margin-top: 10px;
}

.journal-btn:hover { background: var(--color-amber-deep); }
.journal-btn:active { transform: scale(0.98); }

/* Chat Container & Messages */
#chat-box {
  flex: 1;
  width: 100%;
  min-height: 150px;
  border: 1.5px solid var(--color-border-soft);
  border-radius: 8px;
  padding: 12px;
  overflow-y: auto;
  margin-bottom: 12px;
  background: var(--color-washi);
  text-align: left;
  font-size: 0.95rem;
  -webkit-overflow-scrolling: touch;
}

.msg {
  margin-bottom: 10px;
  line-height: 1.4;
  word-break: break-word;
}

.msg.user { color: var(--color-amber-deep); }
.msg.bot { color: var(--color-text-muted); }

/* Chat Inputs */
.input-group {
  display: flex;
  width: 100%;
  gap: 8px;
}

input[type="text"] {
  flex: 1;
  min-height: var(--tap-target-min);
  padding: 12px;
  border: 1.5px solid var(--color-border-soft);
  border-radius: 6px;
  font-size: 17px;
  font-weight: 600;
  outline: none;
  background: var(--color-paper);
  color: var(--color-ink-text);
}

/* Same look as input[type="text"] above, extended to number inputs and
   selects (e.g. the onboarding form's age/nationality/language fields) so
   every form control on the site matches, not just single-line text. */
select,
input[type="number"] {
  width: 100%;
  min-height: var(--tap-target-min);
  padding: 12px;
  border: 1.5px solid var(--color-border-soft);
  border-radius: 6px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  background: var(--color-paper);
  color: var(--color-ink-text);
}

input[type="text"]:focus,
select:focus,
input[type="number"]:focus {
  border-color: var(--color-amber);
}

button {
  min-height: var(--tap-target-min);
  padding: 12px 18px;
  background: var(--color-amber);
  color: var(--color-paper);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background var(--dur-fast);
  white-space: nowrap;
}

button:hover { background: var(--color-amber-deep); }

button:disabled { cursor: default; opacity: 0.85; }

/* Small inline loading spinner, e.g. inside a submit button while an async
   request is in flight. Size/border/margin are set per use-site. */
.spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--color-paper);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Minimal Error / Success Message Views */
.error-view, .message-view {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px 10px;
  margin: auto 0;
}

/* Blank circle outline — a placeholder ornament standing in for a literal icon
   wherever the site previously used an emoji (error states, connection status, etc). */
.error-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--color-text-muted);
  margin: 0 auto 12px auto;
}

.error-text, .message-text {
  font-size: 1.1rem;
  color: var(--color-ink-text);
  line-height: 1.5;
  font-weight: 600;
}

/* Journal page */
.journal-page .card-fill {
  /* Journal always fills the full viewport height, regardless of the
     bare .card-fill responsive cap above — its archive text area is
     absolutely positioned (top/bottom) and needs a fixed-height parent. */
  height: 100vh;
  justify-content: space-between;
  padding: var(--space-5) var(--space-4);
}

.menu-button {
  position: absolute;
  top: calc(var(--space-4) + var(--safe-top));
  right: calc(var(--space-4) + var(--safe-right));
  z-index: 4;
  width: var(--tap-target-min);
  height: var(--tap-target-min);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1.5px solid var(--color-ink-text);
  border-radius: 50%;
  color: var(--color-ink-text);
  font-size: 1.1rem;
  line-height: 1;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}

.menu-button:hover {
  border-color: var(--color-amber);
  background: rgba(201, 154, 82, 0.15);
}

.journal-page .user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 8px;
  background: transparent;
  color: var(--color-text-muted);
  transition: opacity var(--dur-med) ease, visibility var(--dur-med) ease;
}

.journal-page .connection-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--color-amber);
  box-shadow: 0 0 0 2px rgba(201, 154, 82, 0.2);
}

.journal-page .ambient-glow {
  top: 30%;
}

.journal-page .ai-message-section {
  text-align: center;
  z-index: 2;
  /* Clears the top-right menu button (44px tall, offset var(--space-4) from the top)
     with a comfortable margin, now that there's no badge above the title to do it. */
  padding-top: calc(var(--tap-target-min) + var(--space-2));
  transition: opacity var(--dur-med) ease, visibility var(--dur-med);
}

.journal-page .ai-message-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 16px 0;
  padding: 0 14px;
  line-height: 1.35;
  height: 3.4rem;
  white-space: pre-wrap;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--dur-med) ease;
}

.journal-page .ai-message-title.is-fading {
  opacity: 0;
}

.journal-page .ai-divider {
  border: 0;
  height: 1.5px;
  background: var(--color-ink-text);
  margin: 0 auto 18px auto;
  width: 80%;
}

.journal-page .ai-message-text {
  display: none;
}

.journal-page .journal-bg-container {
  position: absolute;
  top: 164px;
  left: 0;
  width: 100%;
  bottom: 40px;
  box-sizing: border-box;
  overflow: hidden;
  z-index: 1;
  cursor: pointer;
}

.journal-page .journal-bg-scroll {
  position: absolute;
  inset: 0;
  padding: 16px 38px 12px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.journal-page .journal-bg-scroll::-webkit-scrollbar {
  display: none;
}

.journal-page .focus-archive-title {
  display: none;
  position: absolute;
  top: 8px;
  left: 38px;
  right: 38px;
  z-index: 3;
  padding-bottom: 8px;
  border-bottom: 1.5px solid var(--color-ink-text);
  color: var(--color-ink-text);
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: left;
}

.journal-page .journal-bg-container::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  height: clamp(40px, 18%, 60px);
  pointer-events: none;
  bottom: 0;
  background: linear-gradient(to top, var(--color-washi) 0%, rgba(255, 255, 255, 0.85) 35%, rgba(255, 255, 255, 0) 100%);
}

.journal-page .journal-bg-text {
  color: rgba(29, 63, 33, 0.28);
  font-family: var(--font-hand);
  font-size: 1rem;
  line-height: 1.35;
  text-align: left;
  word-break: break-all;
  white-space: pre-wrap;
  transition: color var(--dur-slow) ease, opacity var(--dur-slow) ease;
}

.journal-page .card-fill.focus-mode .ai-message-section,
.journal-page .card-fill.focus-mode .input-container-wrapper {
  transition: opacity var(--dur-med) ease, visibility var(--dur-med);
}

.journal-page .card-fill.focus-mode .input-container-wrapper {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.journal-page .card-fill.focus-mode .user-badge {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.journal-page .card-fill.focus-mode .journal-bg-text {
  color: rgba(29, 63, 33, 0.92);
}

.journal-page .card-fill.focus-mode .focus-archive-title {
  display: none;
}

.journal-page .card-fill.focus-mode .journal-bg-scroll {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  padding-left: 38px;
  padding-right: 38px;
}

.journal-page .card-fill.focus-mode .journal-bg-container::after {
  display: none;
}

.journal-page .card-fill.focus-mode .journal-bg-container {
  top: 164px;
  bottom: 40px;
}

.journal-page .input-container-wrapper {
  z-index: 2;
  width: 100%;
  padding-bottom: var(--safe-bottom);
  transition: opacity var(--dur-med) ease, visibility var(--dur-med);
}

/* Shared floating pill-shaped input bar — used by journal's chat input and any other
   page's text-entry needing the same look (e.g. root's trip-goal input). */
.input-card {
  background-color: rgba(253, 251, 245, 0.94);
  border-radius: 16px;
  padding: 12px 12px 12px 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.input-card input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: left;
  color: var(--color-ink-text);
  padding: 8px 0;
}

.input-card button {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  padding: 0;
  background-color: var(--color-amber);
  color: var(--color-paper);
  border: none;
  border-radius: 50%;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform var(--dur-fast) ease, background var(--dur-fast) ease;
}

.input-card button:hover {
  background-color: var(--color-amber-deep);
}

.input-card button:active {
  transform: scale(0.88);
}

.input-card button:disabled {
  background-color: #b8ae9c;
}

/* Journal top-right menu overlay — a bottom sheet offering Home / Audioguide navigation */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-med) ease, visibility var(--dur-med);
}

.menu-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 22, 15, 0.6);
}

.menu-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  box-sizing: border-box;
  background: var(--color-paper);
  border-radius: 20px 20px 0 0;
  padding: var(--space-3) var(--space-4) calc(var(--space-5) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--dur-med) var(--ease-breath);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
}

.menu-overlay.is-open .menu-panel {
  transform: translateY(0);
}

.menu-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border-soft);
  margin: 0 auto var(--space-3) auto;
}

.menu-item {
  width: 100%;
  min-height: var(--tap-target-min);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  color: var(--color-ink-text);
  border: none;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast);
}

.menu-item:hover,
.menu-item:active {
  background: var(--color-amber-soft);
}

.menu-item + .menu-item {
  margin-top: var(--space-1);
  border-top: 1.5px solid var(--color-border-soft);
  border-radius: 0 0 10px 10px;
  padding-top: calc(var(--space-3) + var(--space-1));
}

/* Plain horizontal divider - same weight/color as the journals list's own
   built-in divider (.journal-list-heading's border-top), for use standalone
   between two sections (e.g. under the home page's theme-of-journey block). */
.section-divider {
  width: 100%;
  border-top: 1.5px solid var(--color-border-soft);
  margin: var(--space-5) 0 var(--space-4) 0;
}

/* Home page journals list — one row per tour stop the visitor has journaled at */
.journal-list-heading {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: left;
  width: 100%;
  margin: var(--space-5) 0 var(--space-2) 0;
  padding-top: var(--space-4);
  border-top: 1.5px solid var(--color-border-soft);
}

.journal-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
}

.journal-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: rgba(29, 63, 33, 0.04);
  border: 1px solid rgba(29, 63, 33, 0.12);
  border-radius: 10px;
  text-align: left;
}

.journal-list-item-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--color-ink-text);
  margin: 0;
}

.journal-list-item-btn {
  flex: 0 0 auto;
  min-height: var(--tap-target-min);
  padding: 0 var(--space-4);
  background: var(--color-ink-text);
  color: var(--color-washi);
  border: none;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.journal-list-item-btn:hover {
  background: var(--color-amber-deep);
  color: var(--color-washi);
}

.journal-list-empty {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: var(--space-3) 0;
}

/* Journals popup (index.html's "View Journals" button) — a bottom sheet
   like the main menu/language popup, with its own scrollable region so a
   long list doesn't grow the sheet past the viewport. The heading stays
   fixed at the top of the sheet; only the list below it scrolls. */
.journals-popup-panel {
  max-height: 75vh;
}

.journals-popup-panel .journal-list-scroll {
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.journals-popup-panel .journal-list-scroll::-webkit-scrollbar {
  display: none;
}

.end-journey-btn {
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  min-height: var(--tap-target-min);
  margin-top: var(--space-4);
  padding: 12px 0;
  background: transparent;
  color: var(--color-ink-text);
  border: 1.5px solid var(--color-ink-text);
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.end-journey-btn:hover {
  background: rgba(29, 63, 33, 0.06);
}
