/* Tidal Echo · Ocean Day / Starlight Night
   Ornament stays at the room edges; reading surfaces remain nearly solid. */

/* Persistent page navigation -------------------------------------------------
   Long rooms keep their original back action, but the control floats above the
   reading layer so it never disappears with the page header. */
.tidal-back-anchor {
  display: block;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  pointer-events: none;
}

:is(button, a).tidal-persistent-back {
  position: fixed !important;
  top: calc(env(safe-area-inset-top, 0px) + 11px) !important;
  left: calc(env(safe-area-inset-left, 0px) + 12px) !important;
  /* Above ordinary page chrome, below sheets, lightboxes and full-screen views. */
  z-index: 45 !important;
  display: grid !important;
  place-items: center !important;
  width: 44px !important;
  min-width: 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 1px solid var(--tidal-back-line, rgba(74, 96, 101, .28)) !important;
  border-radius: 50% !important;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, .92) 0 7%, rgba(255, 255, 255, .28) 26%, transparent 47%),
    var(--tidal-back-surface, rgba(247, 252, 251, .91)) !important;
  color: var(--tidal-back-ink, #294b54) !important;
  box-shadow:
    0 10px 28px var(--tidal-back-shadow, rgba(31, 69, 77, .18)),
    inset 0 0 0 1px rgba(255, 255, 255, .38) !important;
  -webkit-backdrop-filter: blur(15px) saturate(1.12) !important;
  backdrop-filter: blur(15px) saturate(1.12) !important;
  font-size: 21px !important;
  line-height: 1 !important;
  text-decoration: none !important;
  cursor: pointer !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease !important;
}

:is(button, a).tidal-persistent-back svg {
  width: 20px !important;
  height: 20px !important;
  margin: 0 !important;
  pointer-events: none;
}

:is(button, a).tidal-persistent-back:focus-visible {
  outline: 2px solid var(--tidal-back-focus, var(--accent, #416e78)) !important;
  outline-offset: 3px !important;
}

@media (hover: hover) {
  :is(button, a).tidal-persistent-back:hover {
    transform: translateY(-1px) !important;
    border-color: var(--tidal-back-focus, var(--accent, #416e78)) !important;
    box-shadow:
      0 13px 31px var(--tidal-back-shadow, rgba(31, 69, 77, .22)),
      inset 0 0 0 1px rgba(255, 255, 255, .46) !important;
  }
}

:is(button, a).tidal-persistent-back:active {
  transform: scale(.93) !important;
}

@media (prefers-reduced-motion: reduce) {
  :is(button, a).tidal-persistent-back { transition: none !important; }
}

:root[data-theme="ocean"] {
  color-scheme: light;
  --wall-default: url("tidal-living-ocean.webp");
  --menu-wall-default: url("tidal-foyer-ocean.webp");
  --bg: #e8f2f3;
  --header-bg: rgba(239, 247, 247, .96);
  --hairline: rgba(66, 105, 113, .22);
  --text: #203746;
  --text-soft: #526d76;
  --text-faint: #738890;
  --bubble-ai-bg: rgba(249, 251, 249, .97);
  --bubble-ai-fg: #203746;
  --bubble-human-bg: rgba(218, 235, 237, .98);
  --bubble-human-fg: #203746;
  --accent: #416e78;
  --send-bg: #315d69;
  --tick: #668792;
  --think-flourish: rgba(65, 110, 120, .46);
  --think-label: #526f78;
  --think-body: #405d67;
  --composer-bg: #e8f2f3;
  --field-bg: rgba(249, 251, 249, .97);
  --field-line: rgba(65, 110, 120, .2);
  --card-bg: rgba(249, 251, 249, .96);
  --card-line: rgba(72, 111, 119, .18);
  --card-shadow: 0 18px 42px rgba(41, 79, 87, .1);
  --seg-track: rgba(68, 107, 116, .13);
  --seg-thumb: rgba(255, 255, 255, .94);
  --slider-track: rgba(65, 110, 120, .28);
  --slider-thumb: #416e78;
  --scrim: linear-gradient(180deg, rgba(238, 247, 247, .28), rgba(232, 242, 243, .58) 42%, rgba(232, 242, 243, .9) 100%);
  --letter-ai-surface:
    linear-gradient(138deg, rgba(255, 255, 255, .7) 0%, rgba(255, 255, 255, .16) 34%, transparent 58%),
    rgba(249, 251, 249, .985);
  --letter-human-surface:
    linear-gradient(138deg, rgba(255, 255, 255, .52) 0%, rgba(255, 255, 255, .1) 38%, transparent 62%),
    rgba(218, 235, 237, .985);
  --letter-line: rgba(145, 119, 70, .3);
  --letter-spine: rgba(65, 110, 120, .32);
  --letter-pearl: #fffdf4;
  --letter-pearl-rim: #a9c8ca;
  --letter-shadow: 0 15px 34px rgba(28, 62, 70, .12), 0 2px 7px rgba(28, 62, 70, .06);
  --tidal-back-surface: rgba(248, 253, 251, .92);
  --tidal-back-line: rgba(74, 118, 124, .34);
  --tidal-back-ink: #294f58;
  --tidal-back-shadow: rgba(31, 74, 82, .19);
  --tidal-back-focus: #416e78;
}

:root[data-theme="starlight"] {
  color-scheme: dark;
  --wall-default: url("tidal-living-starlight.webp");
  --menu-wall-default: url("tidal-foyer-starlight.webp");
  --bg: #07101d;
  --header-bg: rgba(7, 16, 29, .96);
  --hairline: rgba(188, 203, 221, .2);
  --text: #e8e7e2;
  --text-soft: #b5bfca;
  --text-faint: #8c9aa9;
  --bubble-ai-bg: rgba(15, 25, 42, .97);
  --bubble-ai-fg: #e8e7e2;
  --bubble-human-bg: rgba(28, 43, 66, .98);
  --bubble-human-fg: #f0eee8;
  --accent: #b7c6d8;
  --send-bg: #d1bc8a;
  --tick: #90a7bd;
  --accent-fg: #101725;
  --think-flourish: rgba(190, 204, 223, .42);
  --think-label: #aab7c7;
  --think-body: #aeb9c7;
  --composer-bg: #07101d;
  --field-bg: rgba(13, 23, 39, .98);
  --field-line: rgba(190, 204, 223, .2);
  --card-bg: rgba(14, 24, 40, .96);
  --card-line: rgba(190, 204, 223, .18);
  --card-shadow: 0 20px 46px rgba(0, 0, 0, .26);
  --seg-track: rgba(185, 201, 221, .12);
  --seg-thumb: rgba(37, 53, 76, .96);
  --slider-track: rgba(185, 201, 221, .26);
  --slider-thumb: #d1bc8a;
  --scrim: linear-gradient(180deg, rgba(5, 12, 24, .28), rgba(7, 16, 29, .62) 43%, rgba(7, 16, 29, .94) 100%);
  --letter-ai-surface:
    radial-gradient(circle at 88% 15%, rgba(245, 230, 188, .18) 0 1px, transparent 1.8px),
    linear-gradient(138deg, rgba(111, 140, 177, .13) 0%, transparent 44%),
    rgba(14, 24, 41, .985);
  --letter-human-surface:
    radial-gradient(circle at 13% 16%, rgba(245, 230, 188, .18) 0 1px, transparent 1.8px),
    linear-gradient(138deg, rgba(143, 167, 199, .14) 0%, transparent 46%),
    rgba(27, 42, 65, .985);
  --letter-line: rgba(209, 188, 138, .34);
  --letter-spine: rgba(178, 199, 222, .28);
  --letter-pearl: #fbefd0;
  --letter-pearl-rim: #998052;
  --letter-shadow: 0 17px 38px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .2);
  --tidal-back-surface: rgba(9, 18, 32, .9);
  --tidal-back-line: rgba(209, 188, 138, .48);
  --tidal-back-ink: #f1deb0;
  --tidal-back-shadow: rgba(0, 0, 0, .38);
  --tidal-back-focus: #d1bc8a;
}

html[data-theme="ocean"] body {
  --panel: rgba(249, 251, 249, .96);
  --card: rgba(249, 251, 249, .96);
  --line: rgba(65, 104, 112, .19);
  --soft: #526d76;
  --faint: #758990;
  --ink: #315f69;
  --warm: #9b7762;
  --cool: #5c7488;
  --gold: #a98e58;
}

html[data-theme="starlight"] body {
  --panel: rgba(14, 24, 40, .96);
  --card: rgba(14, 24, 40, .96);
  --line: rgba(188, 203, 221, .19);
  --soft: #b5bfca;
  --faint: #8997a7;
  --ink: #9db8c7;
  --warm: #c39b83;
  --cool: #91a8c2;
  --gold: #d1bc8a;
  --text: #e8e7e2;
  --text-soft: #b5bfca;
  --text-faint: #8997a7;
}

html[data-theme] body[data-tidal-scene] {
  background-color: var(--bg) !important;
  background-image: var(--tidal-scene-wall) !important;
  background-position: center top !important;
  background-size: cover !important;
  background-repeat: no-repeat !important;
  background-attachment: fixed !important;
}

html[data-theme="ocean"] body[data-tidal-scene="home"] { --tidal-scene-wall: url("tidal-home-ocean.webp"); }
html[data-theme="ocean"] body[data-tidal-scene="living"] { --tidal-scene-wall: url("tidal-living-ocean.webp"); }
html[data-theme="ocean"] body[data-tidal-scene="bedroom"] { --tidal-scene-wall: url("tidal-bedroom-ocean.webp"); }
html[data-theme="ocean"] body[data-tidal-scene="foyer"] { --tidal-scene-wall: url("tidal-foyer-ocean.webp"); }
html[data-theme="ocean"] body[data-tidal-scene="hisroom"] { --tidal-scene-wall: url("tidal-home-ocean.webp"); }

html[data-theme="starlight"] body[data-tidal-scene="home"] { --tidal-scene-wall: url("tidal-home-starlight.webp"); }
html[data-theme="starlight"] body[data-tidal-scene="living"] { --tidal-scene-wall: url("tidal-living-starlight.webp"); }
html[data-theme="starlight"] body[data-tidal-scene="bedroom"] { --tidal-scene-wall: url("tidal-bedroom-starlight.webp"); }
html[data-theme="starlight"] body[data-tidal-scene="foyer"] { --tidal-scene-wall: url("tidal-foyer-starlight.webp"); }
html[data-theme="starlight"] body[data-tidal-scene="hisroom"] { --tidal-scene-wall: url("tidal-home-starlight.webp"); }

/* Main conversation: room atmosphere at the edges, solid reading bubbles. */
body[data-tidal-scene="living"] .topbar,
body[data-tidal-scene="living"] .composer {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 88%, transparent), color-mix(in srgb, var(--bg) 72%, transparent));
  -webkit-backdrop-filter: blur(16px) saturate(.85);
  backdrop-filter: blur(16px) saturate(.85);
}

body[data-tidal-scene="living"] .peerpill::after {
  content: "";
  display: block;
  width: 54px;
  height: 1px;
  margin: 8px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .6;
}

body[data-tidal-scene="living"] .row.ai .bubble,
body[data-tidal-scene="living"] .row.human .bubble {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 12px 30px rgba(27, 55, 65, .11);
}

/* Conversation stationery: private letters, not generic messenger balloons. */
body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only),
body[data-tidal-scene="living"] .row.human .bubble:not(.att-only) {
  isolation: isolate;
  padding: 12px 17px 13px !important;
  border: 1px solid var(--letter-line) !important;
  border-radius: 19px !important;
  box-shadow: var(--letter-shadow) !important;
}

body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only) {
  background: var(--letter-ai-surface) !important;
  border-top-left-radius: 6px !important;
  box-shadow: inset 3px 0 0 var(--letter-spine), var(--letter-shadow) !important;
}

body[data-tidal-scene="living"] .row.human .bubble:not(.att-only) {
  background: var(--letter-human-surface) !important;
  border-top-right-radius: 6px !important;
  box-shadow: inset -3px 0 0 var(--letter-spine), var(--letter-shadow) !important;
}

body[data-tidal-scene="living"] .row.ai.tail .bubble:not(.att-only) {
  border-bottom-left-radius: 19px !important;
}

body[data-tidal-scene="living"] .row.human.tail .bubble:not(.att-only) {
  border-bottom-right-radius: 19px !important;
}

body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only)::before,
body[data-tidal-scene="living"] .row.human .bubble:not(.att-only)::before {
  content: "";
  position: absolute;
  top: -4px;
  z-index: 2;
  width: 8px;
  height: 8px;
  border: 1px solid color-mix(in srgb, var(--letter-pearl-rim) 74%, transparent);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 25%, #fff 0 18%, var(--letter-pearl) 46%, var(--letter-pearl-rim) 100%);
  box-shadow: 0 2px 5px rgba(20, 39, 50, .2);
}

body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only)::before { left: 15px; }
body[data-tidal-scene="living"] .row.human .bubble:not(.att-only)::before { right: 15px; }

body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only)::after,
body[data-tidal-scene="living"] .row.human .bubble:not(.att-only)::after {
  content: "";
  position: absolute;
  top: 0;
  width: 64px;
  height: 1px;
  opacity: .72;
  background: linear-gradient(90deg, var(--letter-line), transparent);
}

body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only)::after { left: 15px; }
body[data-tidal-scene="living"] .row.human .bubble:not(.att-only)::after {
  right: 15px;
  transform: scaleX(-1);
}

body[data-tidal-scene="living"] .row.ai::before {
  padding: 2px;
  border: 1px solid var(--letter-line);
  outline: 1px solid color-mix(in srgb, var(--letter-line) 48%, transparent);
  outline-offset: 2px;
  background-color: color-mix(in srgb, var(--bg) 92%, transparent);
  background-origin: content-box;
  background-clip: content-box;
  border-radius: 48% 48% 44% 44%;
  box-shadow: 0 10px 25px rgba(19, 43, 54, .16);
}

body[data-tidal-scene="living"] .row.ai::after {
  content: "";
  position: absolute;
  left: calc(var(--avatar-size) + 2px);
  top: calc(clamp(5px, 1vw, 9px) + var(--avatar-size) / 2);
  width: clamp(8px, 1.4vw, 14px);
  height: 1px;
  background: linear-gradient(90deg, var(--letter-line), transparent);
}

body[data-tidal-scene="living"] .bubble:not(.att-only) .txt {
  letter-spacing: .008em;
}

body[data-tidal-scene="living"] .bubble:not(.att-only) .meta {
  opacity: .8;
}

body[data-tidal-scene="living"] .composer .field {
  position: relative;
  border-color: var(--letter-line);
  border-radius: 18px;
  box-shadow: 0 13px 34px rgba(18, 47, 59, .14), inset 0 1px 0 rgba(255, 255, 255, .18);
}

body[data-tidal-scene="living"] .composer .field::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 26px;
  right: 26px;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--letter-line), transparent);
}

/* Daytime composer: a solid writing desk over the illustrated room. */
html[data-theme="ocean"] body[data-tidal-scene="living"] .composer {
  background: linear-gradient(180deg, transparent 0, rgba(232, 242, 243, .86) 28%, #e8f2f3 68%) !important;
  -webkit-backdrop-filter: blur(18px) saturate(.82);
  backdrop-filter: blur(18px) saturate(.82);
}

html[data-theme="ocean"] body[data-tidal-scene="living"] .composer .field {
  background: #fffefa !important;
  border-color: rgba(49, 93, 105, .48) !important;
  box-shadow: 0 13px 34px rgba(18, 47, 59, .2), inset 0 1px 0 #fff !important;
}

html[data-theme="ocean"] body[data-tidal-scene="living"] .composer textarea {
  color: #203746 !important;
  -webkit-text-fill-color: #203746 !important;
  caret-color: #315d69;
  opacity: 1 !important;
}

html[data-theme="ocean"] body[data-tidal-scene="living"] .composer textarea::placeholder {
  color: #526d76 !important;
  -webkit-text-fill-color: #526d76 !important;
  opacity: 1 !important;
}

html[data-theme="ocean"] body[data-tidal-scene="living"] .composer .clip-in-field,
html[data-theme="ocean"] body[data-tidal-scene="living"] .composer .emojibtn {
  color: #315d69 !important;
  opacity: 1 !important;
}

body[data-tidal-scene="living"] .day {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--text-soft);
}

body[data-tidal-scene="living"] .think-block:not(.open) .think-toggle,
body[data-tidal-scene="living"] .act-toggle {
  padding: 5px 9px !important;
  border-radius: 10px !important;
  background: color-mix(in srgb, var(--bg) 91%, transparent) !important;
  box-shadow: 0 6px 18px rgba(20, 46, 57, .07) !important;
}

body[data-tidal-scene="living"] .think-caption .tpv,
body[data-tidal-scene="living"] .act-label {
  opacity: .92 !important;
  color: var(--think-body) !important;
}

/* Hub / home: private residence rather than a hotel lobby. */
body[data-tidal-scene="home"] .app {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 30%, transparent) 0, color-mix(in srgb, var(--bg) 84%, transparent) 34%, var(--bg) 72%);
}

body[data-tidal-scene="home"] header {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(.85);
  backdrop-filter: blur(18px) saturate(.85);
}

body[data-tidal-scene="home"] .entry {
  border-radius: 18px;
  background: var(--panel);
  border-color: color-mix(in srgb, var(--gold) 34%, var(--line));
  box-shadow: 0 18px 42px rgba(23, 52, 61, .11), inset 0 1px rgba(255, 255, 255, .35);
}

body[data-tidal-scene="home"] .copy {
  font-size: 15px;
  line-height: 1.68;
}

/* His room is the densest reading surface: larger type and almost-solid paper. */
body[data-tidal-scene="hisroom"] .wrap {
  background: transparent;
}

body[data-tidal-scene="hisroom"] header {
  margin-top: 2px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  border: 1px solid color-mix(in srgb, var(--gold) 26%, var(--line));
  border-radius: 15px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(.88);
  backdrop-filter: blur(14px) saturate(.88);
  box-shadow: 0 10px 28px rgba(18, 42, 51, .1);
}

body[data-tidal-scene="hisroom"] .room-vista {
  height: clamp(138px, 25vh, 235px);
  position: relative;
  pointer-events: none;
}

body[data-tidal-scene="hisroom"] .room-vista::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 17px;
  height: 1px;
  opacity: .72;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

body[data-tidal-scene="hisroom"] section {
  background: var(--panel);
  border-color: color-mix(in srgb, var(--gold) 28%, var(--line));
  box-shadow: 0 14px 34px rgba(18, 42, 51, .09);
}

body[data-tidal-scene="hisroom"] .mono-item,
body[data-tidal-scene="hisroom"] .diary-text {
  font-size: 17px;
  line-height: 1.78;
}

body[data-tidal-scene="hisroom"] .life-act { font-size: 17px; line-height: 1.78; }
body[data-tidal-scene="hisroom"] .diary-echo { font-size: 15px; line-height: 1.7; }

/* Homepage bell stays in the upper-right and owns the all-room unread state. */
body[data-tidal-scene="living"] .home-bell {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px);
  right: 16px;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--gold) 34%, var(--line));
  border-radius: 50%;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  color: var(--text);
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 28px rgba(20, 42, 55, .13), inset 0 1px rgba(255, 255, 255, .28);
  transition: transform .15s ease, box-shadow .15s ease;
}

body[data-tidal-scene="living"] .home-bell svg { width: 21px; height: 21px; }
body[data-tidal-scene="living"] .home-bell:active { transform: scale(.93); }
body[data-tidal-scene="living"] .home-bell:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 3px; }
body[data-tidal-scene="living"] .home-bell.has-unread { box-shadow: 0 10px 30px rgba(20, 42, 55, .16), 0 0 0 2px color-mix(in srgb, var(--gold) 11%, transparent); }

body[data-tidal-scene="living"] .home-bell-dot {
  display: none;
  position: absolute;
  top: 5px;
  right: 5px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: #df3f50;
  box-shadow: 0 0 0 1px rgba(154, 36, 49, .22), 0 0 14px rgba(223, 63, 80, .76);
}

body[data-tidal-scene="living"] .home-bell-dot.show { display: block; }

/* Diary interactions surfaced from the inbox: clear, tactile and still intimate. */
html[data-theme="ocean"] body[data-tidal-scene="hisroom"] {
  --diary-action-bg: rgba(246, 251, 250, .98);
  --diary-action-line: rgba(65, 110, 120, .2);
  --diary-like-bg: #f8e8e9;
  --diary-like-fg: #974c61;
  --diary-like-line: rgba(151, 76, 97, .34);
  --diary-save-bg: #f6efdc;
  --diary-save-fg: #7c6228;
  --diary-save-line: rgba(124, 98, 40, .34);
  --diary-input-bg: #fffefa;
  --diary-input-fg: #203746;
  --diary-input-placeholder: #627982;
  --diary-input-line: rgba(65, 110, 120, .34);
  --diary-send-bg: #315d69;
  --diary-send-fg: #fff;
  --diary-focus: rgba(65, 110, 120, .22);
}

html[data-theme="starlight"] body[data-tidal-scene="hisroom"] {
  --diary-action-bg: rgba(10, 19, 34, .98);
  --diary-action-line: rgba(209, 188, 138, .24);
  --diary-like-bg: rgba(119, 57, 77, .44);
  --diary-like-fg: #f2b1c1;
  --diary-like-line: rgba(242, 177, 193, .42);
  --diary-save-bg: rgba(139, 110, 50, .34);
  --diary-save-fg: #ead49b;
  --diary-save-line: rgba(234, 212, 155, .42);
  --diary-input-bg: #101c2e;
  --diary-input-fg: #f1eee6;
  --diary-input-placeholder: #acb8c6;
  --diary-input-line: rgba(190, 204, 223, .36);
  --diary-send-bg: #d1bc8a;
  --diary-send-fg: #111a27;
  --diary-focus: rgba(209, 188, 138, .22);
}

body[data-tidal-scene="hisroom"] .diary-actions {
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr) 42px;
  gap: 8px;
  margin-top: 13px;
  padding: 8px;
  border: 1px solid var(--diary-action-line);
  border-radius: 14px;
  background: var(--diary-action-bg);
  box-shadow: 0 9px 24px rgba(17, 39, 50, .1), inset 0 1px 0 rgba(255, 255, 255, .08);
}

body[data-tidal-scene="hisroom"] .diary-actions button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--diary-action-line);
  border-radius: 11px;
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
}

body[data-tidal-scene="hisroom"] .diary-actions button::before {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="抱住"] {
  border-color: var(--diary-like-line);
  background: var(--diary-like-bg);
  color: var(--diary-like-fg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14);
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="抱住"]::before {
  content: "♥";
  font-size: 19px;
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="珍藏"] {
  border-color: var(--diary-save-line);
  background: var(--diary-save-bg);
  color: var(--diary-save-fg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14);
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="珍藏"]::before {
  content: "◆";
  font-size: 16px;
}

body[data-tidal-scene="hisroom"] .diary-actions input {
  min-width: 0;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--diary-input-line);
  border-radius: 11px;
  outline: none;
  background: var(--diary-input-bg);
  color: var(--diary-input-fg);
  box-shadow: inset 0 1px 3px rgba(17, 34, 47, .07);
  font-family: var(--font-cn, inherit);
  font-size: 15px;
}

body[data-tidal-scene="hisroom"] .diary-actions input::placeholder {
  color: var(--diary-input-placeholder);
  opacity: 1;
}

body[data-tidal-scene="hisroom"] .diary-actions input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--diary-focus), inset 0 1px 3px rgba(17, 34, 47, .07);
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="送出"] {
  border-color: transparent;
  background: var(--diary-send-bg);
  color: var(--diary-send-fg);
  box-shadow: 0 6px 16px var(--diary-focus), inset 0 1px 0 rgba(255, 255, 255, .2);
}

body[data-tidal-scene="hisroom"] .diary-actions button[title="送出"]::before {
  content: "➜";
  font-family: var(--font-cn, inherit);
  font-size: 20px;
  transform: translateX(1px);
}

body[data-tidal-scene="hisroom"] .diary-actions button:active {
  transform: scale(.92);
  filter: brightness(.94);
}

body[data-tidal-scene="hisroom"] .diary-actions button:focus-visible {
  outline: 3px solid var(--diary-focus);
  outline-offset: 2px;
}

body[data-tidal-scene="hisroom"] .diary-echo {
  margin-top: 8px;
  padding: 8px 11px;
  border-left: 3px solid var(--diary-save-fg);
  border-radius: 4px 11px 11px 4px;
  background: color-mix(in srgb, var(--diary-action-bg) 92%, transparent);
  color: var(--text-soft);
}

/* Bedroom: keep the scene, but give every long message a quiet opaque surface. */
body[data-tidal-scene="bedroom"] .app {
  background: linear-gradient(180deg, transparent 0, color-mix(in srgb, var(--bg) 76%, transparent) 34%, var(--bg) 72%);
}

body[data-tidal-scene="bedroom"] header,
body[data-tidal-scene="bedroom"] .composer {
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

body[data-tidal-scene="bedroom"] .bub {
  font-size: 20px;
  line-height: 1.68;
  border-color: var(--letter-line);
  border-radius: 18px;
  box-shadow: var(--letter-shadow);
}

body[data-tidal-scene="bedroom"] .row.him .bub { border-top-left-radius: 6px; }
body[data-tidal-scene="bedroom"] .row.me .bub { border-top-right-radius: 6px; }

html[data-theme="ocean"] body[data-tidal-scene="bedroom"] {
  --me: rgba(218, 235, 237, .98);
  --me-fg: #203746;
  --him: rgba(249, 251, 249, .97);
  --him-fg: #203746;
  --ember: #6f8f96;
}

html[data-theme="starlight"] body[data-tidal-scene="bedroom"] {
  --me: rgba(28, 43, 66, .98);
  --me-fg: #f0eee8;
  --him: rgba(15, 25, 42, .97);
  --him-fg: #e8e7e2;
  --ember: #8c6f67;
}

body[data-tidal-scene="bedroom"].mood-rain {
  background-image: linear-gradient(rgba(9, 17, 31, .28), rgba(9, 17, 31, .72)), var(--tidal-scene-wall) !important;
}

body[data-tidal-scene="bedroom"].mood-star {
  background-image: linear-gradient(rgba(7, 14, 29, .08), rgba(7, 14, 29, .48)), url("tidal-bedroom-starlight.webp") !important;
}

/* Foyer / gifts wall: iridescent pearl details are accents, never text backing. */
body[data-tidal-scene="foyer"] {
  --gold-faint: color-mix(in srgb, var(--gold) 22%, transparent);
  --gold-soft: color-mix(in srgb, var(--gold) 42%, transparent);
}

body[data-tidal-scene="foyer"] .gift,
body[data-tidal-scene="foyer"] .gate,
body[data-tidal-scene="foyer"] .lb-card {
  background: var(--panel);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Ocean foyer title needs its own reading plaque over the bright room scene. */
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .wall-head {
  width: min(520px, calc(100% - 8px));
  margin: 14px auto 24px;
  padding: 16px 18px 18px;
  border: 1px solid color-mix(in srgb, var(--gold) 30%, var(--line));
  border-radius: 20px;
  background: rgba(249, 251, 249, .96);
  box-shadow: 0 16px 38px rgba(29, 61, 70, .13), inset 0 1px 0 rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: blur(12px) saturate(.86);
  backdrop-filter: blur(12px) saturate(.86);
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .wall-head .eyebrow {
  color: #315d69;
  opacity: 1;
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .wall-head .title {
  color: #203746;
  text-shadow: none;
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .wall-head .subline {
  color: #526d76;
  opacity: 1;
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .wall-head .title-rule::after {
  background: rgba(249, 251, 249, .98);
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .gate .eyebrow,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .kind-tag,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .lb-kind {
  color: #715a2e;
  opacity: 1;
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .gate p,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .gift-foot,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .lb-foot,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .state,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .state .hint,
html[data-theme="ocean"] body[data-tidal-scene="foyer"] .loading {
  color: #526d76;
}

html[data-theme="ocean"] body[data-tidal-scene="foyer"] .gate input::placeholder {
  color: #607780;
  opacity: 1;
}

/* Group chat has its own legacy color tokens. Pin both themes explicitly so
   the PWA theme never mixes with the phone's prefers-color-scheme setting. */
html[data-theme="ocean"] body[data-tidal-page="rooms"] {
  --ai: rgba(249, 251, 249, .985);
  --ai-fg: #203746;
  --human: rgba(49, 93, 105, .985);
  --human-fg: #fffdf7;
  --ink: #315d69;
  --ok: #256d4d;
  --bad: #9f3b35;
}

html[data-theme="ocean"] body[data-tidal-page="rooms"] .row.ai .bubble:not(.att-only),
html[data-theme="ocean"] body[data-tidal-page="rooms"] .msg-menu-clone.clone-ai {
  background: var(--ai) !important;
  color: var(--ai-fg) !important;
  -webkit-text-fill-color: var(--ai-fg) !important;
}

html[data-theme="ocean"] body[data-tidal-page="rooms"] .row.human .bubble:not(.att-only),
html[data-theme="ocean"] body[data-tidal-page="rooms"] .msg-menu-clone.clone-human {
  background: var(--human) !important;
  color: var(--human-fg) !important;
  -webkit-text-fill-color: var(--human-fg) !important;
}

html[data-theme="ocean"] body[data-tidal-page="rooms"] .row.system .bubble,
html[data-theme="ocean"] body[data-tidal-page="rooms"] .row.thinking .bubble,
html[data-theme="ocean"] body[data-tidal-page="rooms"] .token-live {
  background: rgba(249, 251, 249, .985) !important;
  color: #405d67 !important;
  -webkit-text-fill-color: #405d67 !important;
}

html[data-theme="ocean"] body[data-tidal-page="rooms"] textarea,
html[data-theme="ocean"] body[data-tidal-page="rooms"] input,
html[data-theme="ocean"] body[data-tidal-page="rooms"] .small {
  background: #fffefa;
  color: #203746;
  -webkit-text-fill-color: #203746;
  caret-color: #315d69;
}

html[data-theme="ocean"] body[data-tidal-page="rooms"] textarea::placeholder,
html[data-theme="ocean"] body[data-tidal-page="rooms"] input::placeholder {
  color: #617780;
  -webkit-text-fill-color: #617780;
  opacity: 1;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] {
  --ai: rgba(14, 24, 41, .985);
  --ai-fg: #f1eee6;
  --human: rgba(31, 49, 76, .985);
  --human-fg: #f8f3e8;
  --ink: #d1bc8a;
  --ok: #8fc9aa;
  --bad: #f0a4a9;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .app {
  background: linear-gradient(180deg, rgba(5, 12, 24, .48), rgba(7, 16, 29, .76));
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] header,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .composer {
  background: rgba(7, 16, 29, .86);
  -webkit-backdrop-filter: blur(18px) saturate(.86);
  backdrop-filter: blur(18px) saturate(.86);
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .row.ai .bubble:not(.att-only),
html[data-theme="starlight"] body[data-tidal-page="rooms"] .msg-menu-clone.clone-ai {
  background: var(--ai) !important;
  color: var(--ai-fg) !important;
  -webkit-text-fill-color: var(--ai-fg);
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .row.human .bubble:not(.att-only),
html[data-theme="starlight"] body[data-tidal-page="rooms"] .msg-menu-clone.clone-human {
  background: var(--human) !important;
  color: var(--human-fg) !important;
  -webkit-text-fill-color: var(--human-fg);
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .row.system .bubble {
  background: rgba(13, 23, 39, .97) !important;
  color: #c8d2df !important;
  -webkit-text-fill-color: #c8d2df;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .row.thinking .bubble {
  background: rgba(11, 21, 37, .98) !important;
  color: #c1ccda !important;
  -webkit-text-fill-color: #c1ccda;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .think-fold summary {
  color: #b9c6d5 !important;
  -webkit-text-fill-color: #b9c6d5;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .think-fold summary::after {
  color: #ead49b !important;
  -webkit-text-fill-color: #ead49b;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .think-text {
  color: #eef0ed !important;
  -webkit-text-fill-color: #eef0ed;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .meta,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .token-fixed {
  color: #aebbc9 !important;
  -webkit-text-fill-color: #aebbc9;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .human .meta {
  color: #cbd6e3 !important;
  -webkit-text-fill-color: #cbd6e3;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .token-live {
  background: rgba(12, 23, 39, .97) !important;
  color: #c4d0dd !important;
  -webkit-text-fill-color: #c4d0dd;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] textarea,
html[data-theme="starlight"] body[data-tidal-page="rooms"] input,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .small {
  border-color: rgba(190, 204, 223, .34);
  background: #101c2e;
  color: #f1eee6;
  -webkit-text-fill-color: #f1eee6;
  caret-color: #d1bc8a;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] textarea::placeholder,
html[data-theme="starlight"] body[data-tidal-page="rooms"] input::placeholder {
  color: #acb8c6;
  -webkit-text-fill-color: #acb8c6;
  opacity: 1;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .panel,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .msg-menu-actions {
  background: rgba(10, 19, 34, .985);
  color: #e8e7e2;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .msg-act,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .tab,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .item,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .task-detail {
  color: #e8e7e2;
}

html[data-theme="starlight"] body[data-tidal-page="rooms"] .task-badge,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .small,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .item,
html[data-theme="starlight"] body[data-tidal-page="rooms"] .attach-chip {
  background: rgba(18, 31, 50, .98);
}

/* Repair shop and CC use OS dark-mode media queries for their bubble fills
   while the shared skin supplies text colors. Define their complete palettes
   from the active PWA theme so copy, metadata and composers move together. */
html[data-theme="ocean"] body[data-tidal-page="fix"],
html[data-theme="ocean"] body[data-tidal-page="cc"] {
  --bg: #e8f2f3;
  --panel: rgba(249, 251, 249, .965);
  --text: #203746;
  --soft: #526d76;
  --faint: #617780;
  --accent: #315d69;
  --accent-2: #294f58;
  --me: #d9e9eb;
  --ai: #fffefa;
  --line: rgba(65, 104, 112, .24);
  --code-bg: #172631;
  --code-fg: #d9efe5;
  --danger: #9f3b35;
}

html[data-theme="starlight"] body[data-tidal-page="fix"],
html[data-theme="starlight"] body[data-tidal-page="cc"] {
  --bg: #07101d;
  --panel: rgba(9, 18, 32, .965);
  --text: #f1eee6;
  --soft: #c2ccd8;
  --faint: #a9b6c5;
  --accent: #d1bc8a;
  --accent-2: #ead49b;
  --me: #203652;
  --ai: #101c2e;
  --line: rgba(190, 204, 223, .28);
  --code-bg: #080e18;
  --code-fg: #d9efe5;
  --danger: #f0a4a9;
}

html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .bub,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .title,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .hint,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .meta,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .think {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
}

html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .hint,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .meta,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .think,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) details.think > summary,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .title .sub {
  color: var(--faint);
  -webkit-text-fill-color: var(--faint);
}

html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) #in,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .gate input,
html[data-theme] body[data-tidal-page="cc"] #cfgPrompt {
  background: var(--ai);
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  caret-color: var(--accent);
  opacity: 1;
}

html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) #in::placeholder,
html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .gate input::placeholder,
html[data-theme] body[data-tidal-page="cc"] #cfgPrompt::placeholder {
  color: var(--faint);
  -webkit-text-fill-color: var(--faint);
  opacity: 1;
}

html[data-theme] body:is([data-tidal-page="fix"],[data-tidal-page="cc"]) .act {
  color: var(--code-fg);
  -webkit-text-fill-color: var(--code-fg);
}

html[data-theme="starlight"] body[data-tidal-page="cc"] #send,
html[data-theme="starlight"] body[data-tidal-page="cc"] .gate button,
html[data-theme="starlight"] body[data-tidal-page="cc"] #cfgSave {
  color: #07101d !important;
  -webkit-text-fill-color: #07101d !important;
}

@media (max-width: 640px) {
  body[data-tidal-scene="living"] .row.ai .bubble { max-width: min(78vw, 506px); }
  body[data-tidal-scene="living"] .row.human .bubble { max-width: min(82vw, 506px); }
  body[data-tidal-scene="living"] .row.ai .bubble:not(.att-only),
  body[data-tidal-scene="living"] .row.human .bubble:not(.att-only) { padding: 11px 15px 12px !important; }
  body[data-tidal-scene="living"] .row.think .think-block { max-width: min(78vw, 506px); width: min(78vw, 506px); }
  body[data-tidal-scene="home"] main { padding-top: min(29vh, 245px); }
  body[data-tidal-scene="hisroom"] .wrap { padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 360px) {
  body[data-tidal-scene="hisroom"] .diary-actions {
    grid-template-columns: 38px 38px minmax(0, 1fr) 38px;
    gap: 6px;
    padding: 6px;
  }
  body[data-tidal-scene="hisroom"] .diary-actions button {
    width: 38px;
    height: 38px;
  }
  body[data-tidal-scene="hisroom"] .diary-actions input {
    height: 38px;
    padding: 0 9px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
