/* 小津助手 v2.1 — base: reset, typography, app frame, tab views + transitions, top bar, tab bar.
   Colours and sizes come from css/tokens.css only. Compatibility: no color-mix(), :has(), nesting,
   @container, @layer; no dvh (the frame is position:fixed and JS sets --app-h only while the
   on-screen keyboard overlays the page, see js/main.js setupViewport). */

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
a, label, summary, [role="button"], [data-press] { touch-action: manipulation; }
[role="button"], [data-press], label[for] { cursor: pointer; }
button:disabled { cursor: default; }
input, textarea { margin: 0; }
img, svg { display: block; }
svg.icon { flex: none; }
h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; }
a { color: var(--primary-text); text-underline-offset: 2px; }
[hidden] { display: none !important; }

:focus { outline: none; }
/* Kept in its own rules: iOS < 15.4 drops a whole selector list that contains :focus-visible. */
:focus-visible { outline: none; box-shadow: var(--focus-ring); }

::selection { background: var(--primary-soft); color: var(--text); }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.noscript { padding: var(--sp-8); text-align: center; color: var(--text-2); }

/* ---------- App frame ----------
   position:fixed + top/bottom = the layout viewport (which already shrinks with Android's
   resizes-content keyboard). On iOS the keyboard overlays the page instead; main.js then sets
   html.vv-fit with --app-top/--app-h from visualViewport. */
#auth, #app {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
html.vv-fit #auth, html.vv-fit #app {
  top: var(--app-top);
  bottom: auto;
  height: var(--app-h);
}
#auth { display: none; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
#app { display: none; flex-direction: column; }
html:not(.is-authed) #auth { display: block; }
html.is-authed #app { display: flex; }

/* ---------- Tab views ---------- */
.views { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.view {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.view.is-active { display: flex; z-index: 1; }
.view.is-leaving {
  display: flex;
  z-index: 0;
  pointer-events: none;
  animation: view-out var(--dur-fast) var(--ease-in) both;
}
.view.is-entering { animation: view-in-r var(--dur) var(--ease-out) both; }
.view.is-entering.from-left { animation-name: view-in-l; }
@keyframes view-in-r { from { opacity: 0; transform: translate3d(8px, 0, 0); } to { opacity: 1; transform: none; } }
@keyframes view-in-l { from { opacity: 0; transform: translate3d(-8px, 0, 0); } to { opacity: 1; transform: none; } }
@keyframes view-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.view-error { flex: 1; }

/* Scroll area used by every page */
.page-scroll {
  position: relative; /* contains absolutely positioned .sr-only helpers (tables ignore height:1px) */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--page-x) var(--sp-10);
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  z-index: var(--z-topbar);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--sp-1) + var(--safe-right)) 0 calc(var(--sp-1) + var(--safe-left));
  background: var(--bg);
  box-shadow: 0 1px 0 transparent;
  transition: background-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.topbar.is-scrolled { background: var(--bg-elev); box-shadow: 0 1px 0 var(--line); }
.topbar.is-clear { background: transparent; }
.topbar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  padding: 0 var(--sp-2);
}
.topbar-title.is-center { text-align: center; }
/* Large-title pages: the compact title fades in once the big heading scrolls away */
.topbar.is-large .topbar-title { opacity: 0; transition: opacity var(--dur) var(--ease-out); }
.topbar.is-large.is-scrolled .topbar-title { opacity: 1; }
.topbar-spacer { width: var(--tap); flex: none; }
.topbar-actions { display: flex; flex: none; align-items: center; }

.page-head { padding: var(--sp-3) 0 var(--sp-2); }
.page-title {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
}
.page-sub { margin-top: var(--sp-1); color: var(--text-3); font-size: var(--fs-sm); line-height: var(--lh-ui); }

/* ---------- Tab bar: opaque, sliding pill indicator tinted with the section accent ---------- */
html { --tab-ink: var(--chat-text); --tab-soft: var(--chat-soft); }
html[data-tab="life"] { --tab-ink: var(--life-text); --tab-soft: var(--life-soft); }
html[data-tab="workshop"] { --tab-ink: var(--workshop-text); --tab-soft: var(--workshop-soft); }
html[data-tab="ddz"] { --tab-ink: var(--ddz-text); --tab-soft: var(--ddz-soft); }
html[data-tab="me"] { --tab-ink: var(--me-text); --tab-soft: var(--me-soft); }

.tabbar {
  position: relative;
  z-index: var(--z-tabbar);
  flex: none;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  overflow: hidden;
  background: var(--bg-elev);
  box-shadow: 0 -1px 0 var(--line);
  transition: height var(--dur) var(--ease-out);
}
.tabbar-inner {
  position: relative;
  display: flex;
  max-width: 520px;
  height: var(--tabbar-h);
  margin: 0 auto;
  padding: 0 calc(var(--sp-1) + var(--safe-right)) 0 calc(var(--sp-1) + var(--safe-left));
  transition: transform var(--dur) var(--ease-out);
}
/* One pill that slides between tabs (js/motion.js positions it with --ind-x / --ind-w). */
.tab-indicator {
  position: absolute;
  top: 7px;
  left: 0;
  width: var(--ind-w, 56px);
  height: 30px;
  border-radius: var(--r-full);
  background: var(--tab-soft);
  transform: translate3d(var(--ind-x, -100px), 0, 0);
  transition: transform var(--dur-slow) var(--ease-out), background-color var(--dur-slow) var(--ease-out), width var(--dur-slow) var(--ease-out);
  pointer-events: none;
}
.tab-indicator.no-anim { transition: none; }
.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding-top: 7px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  line-height: 16px;
  transition: color var(--dur) var(--ease-out);
}
.tab-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 30px;
  transition: transform var(--dur) var(--ease-out);
}
.tab .icon { width: 24px; height: 24px; --dt: 0; transition: transform var(--dur) var(--ease-out); }
.tab-label { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tab[aria-current="page"] { color: var(--tab-ink); font-weight: var(--fw-semibold); }
.tab[aria-current="page"] .icon { --dt: 0.3; animation: tab-pop var(--dur-slow) var(--ease-spring); }
.tab:active .tab-icon, .tab.is-pressed .tab-icon { transform: scale(0.9); transition-duration: var(--dur-press); }
@keyframes tab-pop { 0% { transform: scale(0.84); } 100% { transform: scale(1); } }
/* Fallback before js/motion.js measures the tabs: tint the active icon slot itself. */
.tabbar:not(.has-indicator) .tab[aria-current="page"] .tab-icon { border-radius: var(--r-full); background: var(--tab-soft); }

/* Hidden while typing in chat (keyboard) or during an immersive 斗地主 game */
html.composer-focus[data-tab="chat"] .tabbar { height: 0; box-shadow: none; transition: none; }
html.ddz-immersive[data-tab="ddz"] .tabbar { height: 0; box-shadow: none; }
html.ddz-immersive[data-tab="ddz"] .tabbar-inner { transform: translateY(100%); }

/* ---------- 斗地主 host (the module itself is owned by the 斗地主 UI workstream) ---------- */
.ddz-host { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; }
.ddz-loading { display: flex; flex: 1; align-items: center; justify-content: center; gap: var(--sp-2); color: var(--text-3); font-size: var(--fs-sm); }
.ddz-empty { flex: 1; padding-top: calc(var(--safe-top) + var(--sp-10)); }

/* ---------- Reduced motion: opacity only, no transforms ---------- */
@media (prefers-reduced-motion: reduce) {
  .view.is-entering, .view.is-entering.from-left { animation-name: fade-in; }
  .tab[aria-current="page"] .icon { animation: none; }
  .tab:active .tab-icon, .tab.is-pressed .tab-icon { transform: none; }
  .tab-indicator { transition: background-color var(--dur) linear; }
  html { scroll-behavior: auto; }
}

/* ---------- Wide screens: centred column, tab bar stays at the bottom ---------- */
@media (min-width: 768px) {
  .tabbar-inner { max-width: 480px; }
  .topbar {
    padding-left: max(var(--sp-1), calc((100% - var(--content-max)) / 2));
    padding-right: max(var(--sp-1), calc((100% - var(--content-max)) / 2));
  }
}
