/* THE BLUE HOUSE 勝浦 — in-stay chat.
   The guide site (bluehouse-katsuura.surge.sh) is the brand: cobalt ink, ice
   type, one bronze accent. Its tokens are reproduced here verbatim so the two
   surfaces read as one property. No web fonts and no remote assets — this runs
   on a LAN, so the type is a per-language system stack.
   Layout is written in logical properties throughout: Arabic mirrors because
   the box model mirrors, not because of a parallel RTL stylesheet. */

/* ============ Tokens ============ */
:root {
  --ink:           #04081F;
  --ink-2:         #0A1340;
  --cobalt-deep:   #0A1B66;
  --cobalt-core:   #1538C8;

  --neon-ice:      #E8F2FF;
  --neon-soft:     #BFD4EE;
  --neon-glow:     #7FD4FF;

  --bronze:        #C9A26B;
  --bronze-deep:   #8A5A2A;

  --rule:          rgba(232, 242, 255, 0.10);
  --rule-strong:   rgba(232, 242, 255, 0.22);
  --surface:       rgba(232, 242, 255, 0.045);
  --surface-hi:    rgba(232, 242, 255, 0.09);

  --space-2xs: 4px;
  --space-xs:  8px;
  --space-sm:  12px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  --radius:     16px;
  --radius-sm:  8px;
  --radius-tuck: 5px;
  --tap:        44px;

  --t-micro: 11px;
  --t-ui:    13.5px;
  --t-body:  15px;

  --ease: cubic-bezier(0.25, 1, 0.5, 1);

  --font-mark: Baskerville, "Hoefler Text", "Times New Roman", Times, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-body: var(--font-ui);
}
html[lang="ja"] { --font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans CJK JP", Meiryo, var(--font-ui); }
html[lang="zh"] { --font-body: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", var(--font-ui); }
html[lang="ko"] { --font-body: "Apple SD Gothic Neo", "Noto Sans CJK KR", "Malgun Gothic", var(--font-ui); }
html[lang="ar"] { --font-body: "Geeza Pro", "Al Bayan", "Noto Sans Arabic", var(--font-ui); }

/* ============ Reset ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  block-size: 100%;
  background: var(--ink);
  color: var(--neon-ice);
  font-family: var(--font-body);
  font-size: var(--t-body);
  line-height: 1.7; /* light type on dark reads lighter: extra leading */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { overscroll-behavior: none; }
button, textarea, select { font: inherit; color: inherit; background: none; border: 0; }
button { cursor: pointer; }
svg { display: block; }

.sr-only {
  position: absolute; inline-size: 1px; block-size: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

:where(button, select, textarea, a):focus-visible {
  outline: 2px solid var(--neon-glow);
  outline-offset: 2px;
}

/* ============ Frame ============ */
.app {
  block-size: var(--app-h, 100dvh);
  max-inline-size: 460px;
  margin-inline: auto;
  display: grid;
  /* One column that is allowed to be narrower than its content: the chip row
     scrolls, and without this a grid item's auto minimum makes the whole app
     as wide as the chips and the phone scrolls sideways. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto auto;
  background: var(--ink);
  overflow: hidden;
}
@media (min-width: 560px) {
  /* Off the phone the widget stops being the whole screen and becomes the
     object the guide site already is: one lit column on deep water. */
  body {
    background: #02040E;
    min-block-size: var(--app-h, 100dvh);
    display: grid;
    align-content: center;
    padding-block: var(--space-lg);
  }
  .app {
    block-size: min(var(--app-h, 100dvh) - var(--space-xl), 760px);
    border-radius: var(--radius);
    box-shadow: 0 0 0 1px rgba(127, 212, 255, 0.09), 0 24px 64px rgba(0, 0, 0, 0.55);
  }
}

/* ============ Chrome ============ */
.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: rgba(4, 8, 31, 0.88);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  padding-block-start: max(var(--space-sm), env(safe-area-inset-top));
}
.mark { display: flex; flex-direction: column; gap: 3px; min-inline-size: 0; }
.mark-name {
  font-family: var(--font-mark);
  font-size: 15px;
  line-height: 1;
  letter-spacing: 0.17em;
  color: var(--neon-ice);
  white-space: nowrap;
}
.mark-sub {
  font-family: var(--font-body);
  font-size: var(--t-micro);
  line-height: 1.2;
  letter-spacing: 0.1em;
  color: var(--neon-soft);
  opacity: 0.75;
}

/* The language control is a real <select>: the OS picker is better on a phone
   than anything re-implemented, and it mirrors for free. */
.lang {
  position: relative;
  /* Auto start margin rather than relying on space-between alone: the header
     grows a third child in embed mode and the language pill must stay beside
     it, not halfway across. With two children the two are identical — and the
     margin is here rather than on .mark because .mark carries dir="ltr", which
     is what a logical margin on it would resolve against. */
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  block-size: 34px;
  padding-inline: 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(127, 212, 255, 0.04);
  color: var(--neon-soft);
  flex: none;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.lang:hover, .lang:focus-within { border-color: var(--rule-strong); color: var(--neon-ice); }
.lang-code {
  font-family: var(--font-ui);
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  min-inline-size: 16px;
  text-align: center;
}
.lang-caret { inline-size: 10px; block-size: 6px; opacity: 0.7; }
.lang-select {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  min-block-size: var(--tap);
  margin-block: auto;
  opacity: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.lang-select option { background: var(--ink-2); color: var(--neon-ice); }

/* The guide site's horizon line, kept as the one piece of ornament. */
.horizon {
  block-size: 1px;
  background: linear-gradient(90deg, transparent, rgba(127, 212, 255, 0.3), transparent);
}

/* ============ Thread ============ */
.thread {
  min-inline-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-lg) var(--space-md) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}
/* Conversations grow from the bottom, like every messenger a guest has used.
   margin-block-start:auto on the first child rather than justify-content:
   flex-end, which makes overflowing content unreachable above the scroll. */
.thread > :first-child { margin-block-start: auto; }
/* Before anything is said there is no conversation to anchor: the invitation
   sits in the middle of the room instead of at the bottom of it. */
.thread > .intro:only-child { margin-block: auto; }
.thread::-webkit-scrollbar { inline-size: 6px; }
.thread::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

.intro {
  align-self: center;
  max-inline-size: 30ch;
  text-align: center;
  font-size: var(--t-ui);
  line-height: 1.75;
  color: var(--neon-soft);
  opacity: 0.85;
  padding-block: var(--space-lg);
  text-wrap: balance;
}

.msg {
  max-inline-size: 84%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  animation: rise 0.28s var(--ease) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

.msg-guest { margin-inline-start: auto; align-items: flex-end; }
.msg-bot   { margin-inline-end: auto; }

.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: pre-line;
  overflow-wrap: anywhere;
  font-size: var(--t-body);
}
.msg-guest .bubble {
  background: var(--cobalt-core);
  color: #F2F7FF;
  border-end-end-radius: var(--radius-tuck);
}
.msg-bot .bubble {
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--neon-ice);
  border-end-start-radius: var(--radius-tuck);
}

/* needs_staff is not a failure — it is the product working. It reads as a
   handover, in bronze, never in an error colour. */
.msg-staff .bubble {
  background: rgba(201, 162, 107, 0.07);
  border-color: rgba(201, 162, 107, 0.38);
}
.staff-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-block-end: 7px;
  font-family: var(--font-ui);
  font-size: var(--t-micro);
  letter-spacing: 0.1em;
  color: var(--bronze);
}
.staff-badge::before {
  content: "";
  inline-size: 5px; block-size: 5px;
  border-radius: 50%;
  background: var(--bronze);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* The guide link is part of the answer: several answers point at video and
   photos that only exist there. Sized as a real target, not a footnote. */
.guide-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-block-size: var(--tap);
  margin-block-start: var(--space-xs);
  padding-inline: 15px;
  border: 1px solid rgba(201, 162, 107, 0.5);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: var(--t-ui);
  color: var(--bronze);
  text-decoration: none;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.guide-btn:hover { background: rgba(201, 162, 107, 0.12); border-color: var(--bronze); color: #E4C695; }
.guide-btn:active { transform: scale(0.98); }
.guide-btn svg { inline-size: 13px; block-size: 13px; }
[dir="rtl"] .guide-btn svg { transform: scaleX(-1); }

/* Failure state: a plain line the guest can act on. Never the server's words. */
.notice {
  align-self: center;
  max-inline-size: 32ch;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--t-ui);
  line-height: 1.6;
  color: var(--neon-soft);
  animation: rise 0.28s var(--ease) both;
}
.retry-btn {
  min-block-size: var(--tap);
  padding-inline: 18px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  font-size: var(--t-ui);
  color: var(--neon-ice);
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.retry-btn:hover { background: var(--surface-hi); border-color: var(--neon-glow); }

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 15px 16px;
}
.typing i {
  inline-size: 5px; block-size: 5px;
  border-radius: 50%;
  background: var(--neon-soft);
  animation: blink 1.3s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 45% { opacity: 1; } }

/* ============ Quick topics ============ */
.topics { padding-block: var(--space-sm) 0; }
.topics-label {
  padding-inline: var(--space-md);
  margin-block-end: var(--space-xs);
  font-family: var(--font-ui);
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--neon-soft);
  opacity: 0.72;
}
.chips {
  --fade-to: right;
  min-inline-size: 0;
  display: flex;
  gap: var(--space-xs);
  padding-inline: var(--space-md);
  padding-block-end: var(--space-2xs);
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-mask-image: linear-gradient(to var(--fade-to), #000 calc(100% - 30px), transparent);
  mask-image: linear-gradient(to var(--fade-to), #000 calc(100% - 30px), transparent);
}
[dir="rtl"] .chips { --fade-to: left; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-block-size: var(--tap);
  padding-inline: 15px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--t-ui);
  color: var(--neon-soft);
  white-space: nowrap;
  scroll-snap-align: start;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.12s var(--ease);
}
.chip:hover { background: var(--surface-hi); color: var(--neon-ice); border-color: var(--rule-strong); }
.chip:active { transform: scale(0.97); }
.chip[disabled] { opacity: 0.4; }

/* ============ Composer ============ */
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  padding-block-end: max(var(--space-sm), env(safe-area-inset-bottom));
  border-block-start: 1px solid var(--rule);
  background: rgba(4, 8, 31, 0.9);
}
.input {
  flex: 1;
  min-inline-size: 0;
  min-block-size: var(--tap);
  max-block-size: 132px;
  padding: 11px 15px;
  border: 1px solid var(--rule);
  border-radius: 22px;
  background: var(--surface);
  color: var(--neon-ice);
  caret-color: var(--neon-glow);
  font-size: var(--t-body);
  line-height: 1.45;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.input::placeholder { color: var(--neon-soft); opacity: 0.62; }
.input:focus { outline: none; border-color: rgba(127, 212, 255, 0.45); background: var(--surface-hi); }
.input:disabled { opacity: 0.55; }

.send {
  flex: none;
  inline-size: var(--tap);
  block-size: var(--tap);
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--neon-soft);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.12s var(--ease);
}
.send svg { inline-size: 20px; block-size: 20px; }
[dir="rtl"] .send svg { transform: scaleX(-1); }
.send.ready {
  background: var(--bronze);
  border-color: var(--bronze);
  color: var(--ink);
}
.send.ready:hover { background: #DBB47F; border-color: #DBB47F; }
.send:active { transform: scale(0.94); }
.send:disabled { cursor: default; opacity: 0.45; }
.send:disabled:active { transform: none; }

/* The way out of the panel, and the only one a phone has: at full screen the
   launcher bubble is underneath the chat, so this button is it. Sized and shaped
   like .send — same 44px box, same hairline — because it lives in the same
   chrome. Hidden outside embed mode, where the browser's own back is the way out
   and a third header child would change a page that must not change. */
.close {
  display: none;
  place-items: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--neon-soft);
  flex: none;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.12s var(--ease);
}
.close svg { inline-size: 18px; block-size: 18px; }
.close:hover { background: var(--surface-hi); color: var(--neon-ice); border-color: var(--rule-strong); }
.close:active { transform: scale(0.94); }

/* ============ Embed mode ============ */
/* Inside the launcher's panel the widget is not a page on a desktop any more:
   the panel is already the lit column on deep water, with its own radius and its
   own shadow. Repeating them would be a card inside a card, so the app simply
   fills the frame it was given. Everything here is scoped to html.embed, which
   only ?embed=1 sets — the standalone page is untouched. */
html.embed body {
  background: var(--ink);
  display: block;
  min-block-size: 0;
  padding-block: 0;
}
html.embed .app {
  max-inline-size: none;
  block-size: var(--app-h, 100dvh);
  border-radius: 0;
  box-shadow: none;
}
html.embed .close { display: grid; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
