/* V1.13: quiet, monochrome fluid surfaces. No continuous background animation. */
:root {
  --gutter: max(clamp(16px, 3vw, 88px), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --radius: clamp(16px, 1.45vw, 26px);
  --radius-sm: 12px;
  --ease-fluid: cubic-bezier(.22, 1, .36, 1);
  --motion-fast: 180ms;
  --motion-flow: 380ms;
  --glass: rgba(19, 19, 21, .9);
  --glint: rgba(255, 255, 255, .045);
  --hover-line: #57575e;
  --panel-shadow: 0 12px 36px rgba(0, 0, 0, .12);
}
html[data-theme="light"] {
  --glass: rgba(250, 250, 249, .92);
  --glint: rgba(255, 255, 255, .8);
  --hover-line: #aaaab0;
  --panel-shadow: 0 12px 36px rgba(25, 25, 30, .045);
}
html { scroll-padding-top: 100px; }
body { font-size: clamp(14px, calc(12px + .3vw), 20px); }
.page, .nav-wrap {
  width: calc(100% - var(--gutter) * 2);
  max-width: 2560px;
}
.page { padding-block: clamp(24px, 3vw, 52px) clamp(28px, 4vw, 72px); }
.topbar {
  height: clamp(68px, 5vw, 86px);
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
html[data-theme="light"] .topbar { background: var(--glass); }
.brand { font-size: clamp(20px, 1.45vw, 27px); }
.nav { position: relative; isolation: isolate; }
.nav a {
  position: relative;
  z-index: 1;
  border-radius: var(--radius-sm);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, .95vw, 19px);
  /* Keep text crisp; the capsule supplies motion without repainting every glyph. */
  transition: none;
}
.nav a.active { border-radius: var(--radius-sm); }
.nav .nav-indicator {
  position: absolute;
  inset: 0 auto auto 0;
  z-index: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--glint), transparent), var(--surface-2);
  box-shadow: inset 0 1px 0 var(--glint);
  transition: transform 260ms var(--ease-fluid), opacity var(--motion-fast) ease;
}
.nav.has-indicator a.active, .nav.has-indicator a:hover,
html[data-theme="light"] .nav.has-indicator a.active,
html[data-theme="light"] .nav.has-indicator a:hover { background: transparent; }
.nav:not(.indicator-ready) .nav-indicator { visibility: hidden; transition: none; }
.session-actions { gap: 12px; }
.current-user { font-size: clamp(12px, .85vw, 16px); }
.menu-button, .logout-button { min-height: 40px; border-radius: 10px; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }

/* Soft surfaces, not floating coloured blobs. Shadows stay static while moving. */
.welcome-panel, .intro-panel, .announcement-board, .android-download-panel,
.settings-card, .about-version-card, .docs-version-card, .docs-pending,
.auth-layout, .mc-guide-box, .mc-plan-box, .chat-sidebar, .chat-shell {
  border-radius: var(--radius);
}
.welcome-panel, .android-download-panel, .about-version-card, .docs-version-card {
  background-image: linear-gradient(135deg, var(--glint), transparent 58%);
}
.welcome-panel, .intro-panel, .announcement-board, .android-download-panel,
.settings-card, .about-version-card {
  transition: border-color var(--motion-fast) ease, transform var(--motion-flow) var(--ease-fluid);
}
.home-grid { grid-template-columns: minmax(0, .82fr) minmax(0, 1.18fr); gap: clamp(16px, 1.65vw, 34px); }
.home-left, .home-right { gap: clamp(16px, 1.35vw, 26px); }
.welcome-panel, .intro-panel, .announcement-board, .android-download-panel {
  padding: clamp(20px, 2vw, 38px);
}
.welcome-panel { min-height: 0; }
.welcome-panel h1 { font-size: clamp(32px, 3.2vw, 62px); }
.welcome-panel > p:not(.welcome-label), .intro-panel > p, .announcement-text {
  font-size: clamp(14px, 1.05vw, 20px);
  line-height: 1.85;
}
.welcome-label, .intro-panel li a { font-size: clamp(13px, .95vw, 18px); }
.intro-panel li a { padding-block: 14px; }
.carousel {
  height: clamp(320px, 33vw, 620px);
  border-radius: var(--radius);
  isolation: isolate;
}
.carousel-slide { transition: opacity 600ms ease, visibility 600ms; }
.slide-caption strong { font-size: clamp(18px, 1.5vw, 28px); }
.slide-caption span { font-size: clamp(12px, 1vw, 18px); }
.carousel-arrow { width: 42px; height: 44px; border-radius: 12px; }
.carousel-pause {
  position: absolute; z-index: 2; top: 14px; right: 14px;
  min-height: 36px; padding: 7px 12px; border-radius: 20px;
  border: 1px solid #ffffff55; background: #111111aa; color: #fff;
  font-size: 12px;
}
.carousel-pause:disabled { cursor: default; }
.carousel-dots button { position: relative; min-width: 24px; min-height: 24px; background: none; border: 0; }
.carousel-dots button::after { content: ''; position: absolute; width: 6px; height: 6px; inset: 9px; border-radius: 8px; background: #ffffff70; transition: transform var(--motion-fast), background var(--motion-fast); }
.carousel-dots button.is-active { background: none; }
.carousel-dots button.is-active::after { background: #fff; transform: scale(1.4); }
.client-download-actions { gap: 10px; flex-wrap: wrap; }

.button, .docs-download-button, .menu-button, .logout-button {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  touch-action: manipulation;
  transition: background var(--motion-fast) ease, border-color var(--motion-fast) ease,
              color var(--motion-fast) ease, transform var(--motion-fast) var(--ease-fluid);
}
.button { border-radius: 12px; min-height: 44px; font-size: clamp(13px, .95vw, 18px); padding: 11px 17px; }
.button:active:not(:disabled), .docs-download-button:active:not(:disabled), .menu-button:active, .logout-button:active { transform: scale(.98); }
.interaction-ripple { position: absolute; pointer-events: none; border-radius: 50%; background: currentColor; opacity: .12; z-index: -1; }
.form-stack input, .form-stack textarea, .theme-setting select,
.add-friend-form input, .user-search input, .user-delete-panel input { border-radius: 10px; }
.form-stack input, .form-stack textarea, .theme-setting select {
  transition: border-color var(--motion-fast) ease, background var(--motion-fast) ease;
}
.form-stack input:focus, .form-stack textarea:focus, .add-friend-form input:focus { border-color: var(--muted); }
.account-action { border-radius: 16px; }
.form-stack label, .settings-card > p, .settings-note { font-size: clamp(14px, .95vw, 20px); }
.form-stack input, .form-stack textarea { font-size: clamp(16px, 1vw, 22px); }
.form-stack label small, .theme-setting small { font-size: clamp(12px, .85vw, 17px); }
.theme-setting strong, .account-action h3 { font-size: clamp(16px, 1.15vw, 23px); }
.form-stack input:not([type="checkbox"]):not([type="hidden"]) { min-height: 44px; }
html[data-theme="light"] .welcome-panel, html[data-theme="light"] .android-download-panel,
html[data-theme="light"] .about-version-card, html[data-theme="light"] .docs-version-card {
  background-image: linear-gradient(135deg, var(--glint), transparent 58%);
}
.account-action > p { min-height: 3.2em; color: var(--muted); }
.settings-layout { grid-template-columns: clamp(180px, 17vw, 270px) minmax(0, 1fr); }
.settings-sidebar { border-radius: 16px; top: 106px; }
.settings-sidebar a, .docs-nav a { border-radius: 10px; min-height: 44px; }
.settings-content, .account-settings-grid, .account-action, .settings-form, .theme-setting > span { min-width: 0; }
.theme-setting { max-width: none; }
.theme-setting select { flex-shrink: 0; max-width: 100%; min-height: 44px; font-size: 16px; }
.motion-setting { border-top: 1px solid var(--line); }
.theme-setting small { line-height: 1.7; }
.docs-sidebar { top: 106px; height: calc(100dvh - 136px); }
.docs-topic { border-radius: 12px; padding-inline: 12px; transition: background var(--motion-fast) ease; }
.docs-download-button { border-radius: 12px; }
.download-panel, .notice, .flash, .remembered-login { border-radius: 12px; }
.about-version-card { box-shadow: var(--panel-shadow); }
.release-row { border-radius: 12px; transition: background var(--motion-fast) ease; }

/* Do not transform the chat viewport or animate its history. Preserve fixed popups and the keyboard. */
body.chat-body .topbar { padding-top: env(safe-area-inset-top, 0px); height: calc(clamp(68px, 5vw, 86px) + env(safe-area-inset-top, 0px)); }
body.chat-body .page.chat-page { width: calc(100% - var(--gutter) * 2); max-width: 2560px; height: auto; padding-block: clamp(10px, 1.3vw, 22px); }
body.chat-body .chat-layout { grid-template-columns: clamp(220px, 20vw, 340px) minmax(0, 1fr); gap: clamp(12px, 1.2vw, 24px); }
.chat-sidebar-head { padding: 20px; }
.conversation { border-radius: 12px; min-height: 48px; }
.conversation-copy strong { overflow-wrap: anywhere; }
.chat-composer { border-radius: 0 0 var(--radius) var(--radius); }
.chat-composer textarea { font-size: clamp(16px, 1vw, 22px); border-radius: 12px; background: var(--bg); color: var(--text); border-color: var(--line); }
.chat-composer textarea::placeholder { color: var(--muted); }
.message { border-radius: 14px; }
.message-list { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.add-friend-details { border-radius: 12px; }
.add-friend-details summary { min-height: 44px; display: flex; align-items: center; }

@media (hover: hover) and (pointer: fine) {
  .welcome-panel:hover, .android-download-panel:hover, .about-version-card:hover { transform: translateY(-2px); border-color: var(--hover-line); }
  .docs-topic:hover, .release-row:hover { background: var(--surface); }
}
@media (min-width: 1101px) {
  .account-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1600px) {
  .form-stack label, .settings-card > p, .settings-note { font-size: clamp(15px, .95vw, 20px); }
  .form-stack input, .form-stack textarea { font-size: clamp(16px, 1vw, 22px); }
  .message-body { font-size: clamp(16px, 1vw, 22px); }
}
@media (max-width: 1100px) {
  .settings-layout { grid-template-columns: 180px minmax(0, 1fr); }
  .account-settings-grid { grid-template-columns: 1fr; }
  .account-action > p { min-height: 0; }
}
@media (max-width: 1000px) {
  .topbar { height: calc(68px + env(safe-area-inset-top, 0px)); padding-top: env(safe-area-inset-top, 0px); }
  .nav-content, html[data-theme="light"] .nav-content { background: var(--surface); border-radius: 0 0 20px 20px; padding-inline: var(--gutter); box-shadow: var(--panel-shadow); max-height: calc(100dvh - 80px); overflow-y: auto; }
  .nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .nav a { justify-content: center; padding: 12px 8px; }
  .session-actions { padding-block: 12px 0; }
  .home-grid { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
  .home-left { display: flex; }
  .carousel { height: clamp(300px, 40vw, 430px); }
}
@media (max-width: 780px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-left { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-left .android-download-panel { grid-column: 1 / -1; }
  .welcome-panel, .intro-panel { min-height: 0; }
  .carousel { height: clamp(270px, 54vw, 430px); }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-sidebar { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-setting { flex-direction: row; align-items: center; }
  .theme-setting select { min-width: 160px; width: auto; }
  .docs-sidebar { position: static; height: auto; }
}
@media (max-width: 700px) {
  html { scroll-padding-top: 86px; }
  .nav-wrap { padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px); }
  body.chat-body .topbar { height: calc(68px + env(safe-area-inset-top, 0px)); }
  body.chat-body .page.chat-page { width: 100%; padding: 0; max-width: none; }
  body.chat-body .chat-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 0; }
  body.chat-body .chat-sidebar { border-radius: 0; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); min-height: 58px; max-height: 64px; }
  body.chat-body .chat-shell { border-radius: 0; border-top: 0; border-bottom: 0; }
  .chat-composer { border-radius: 0; }
  body.chat-body .chat-composer { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .conversation { min-height: 44px; }
  .conversation-copy { max-width: 120px; }
  .conversation-copy strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .add-friend-details { position: sticky; right: 0; z-index: 3; background: var(--surface); box-shadow: -8px 0 12px var(--surface); }
  .add-friend-details:not([open])::after { content: ""; position: absolute; top: -8px; bottom: -8px; right: -9px; width: 9px; background: var(--surface); pointer-events: none; }
  .add-friend-details summary { padding: 8px 12px; font-size: 13px; }
  body.chat-body .add-friend-details[open] { z-index: 30; border-radius: 18px; padding: 6px; max-height: calc(var(--chat-viewport-height, 100dvh) - 100px); }
  body.chat-body .add-friend-form input { min-height: 44px; }
  .auth-layout { border-radius: 0; }
  .form-stack input:not([type="checkbox"]):not([type="hidden"]), .form-stack textarea, .user-search input, .user-delete-panel input { font-size: 16px; min-height: 44px; }
}
@media (max-width: 560px) {
  .home-left { grid-template-columns: minmax(0, 1fr); }
  .home-left .android-download-panel { grid-column: auto; }
  .home-grid, .home-left, .home-right { gap: 14px; }
  .welcome-panel, .intro-panel, .announcement-board, .android-download-panel { padding: 20px; }
  .welcome-panel h1 { font-size: clamp(30px, 8vw, 42px); }
  .carousel { height: clamp(250px, 78vw, 380px); }
  .carousel-arrow { width: 36px; }
  .carousel-pause { top: 12px; right: 12px; }
  .settings-card { padding: 18px; }
  .account-action { padding: 16px; }
  .theme-setting { flex-direction: column; align-items: stretch; gap: 12px; }
  .theme-setting select { width: 100%; min-width: 0; }
  .remembered-device-row { flex-wrap: wrap; gap: 12px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .topbar, body.chat-body .topbar { height: calc(48px + env(safe-area-inset-top, 0px)); }
  .nav a { padding-block: 7px; }
  body.chat-body .page.chat-page { padding-block: 0; }
  body.chat-body .chat-sidebar { border-radius: 0; }
  body.chat-body .chat-shell { border-radius: 0; }
  .chat-composer { border-radius: 0; }
  .chat-composer .button { min-height: 36px; padding-block: 6px; }
}
/* Low-budget devices get the same layout and static surface, without blur or motion. */
html[data-effects="lite"] .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg); }
html[data-effects="lite"] .welcome-panel:hover, html[data-effects="lite"] .android-download-panel:hover, html[data-effects="lite"] .about-version-card:hover { transform: none; }
html[data-motion="reduced"] { --motion-fast: 0ms; --motion-flow: 0ms; scroll-behavior: auto; }
html[data-motion="reduced"] *, html[data-motion="reduced"] *::before, html[data-motion="reduced"] *::after {
  scroll-behavior: auto !important; animation: none !important; transition: none !important;
}
html[data-motion="reduced"] .button:hover, html[data-motion="reduced"] .button:active,
html[data-motion="reduced"] .welcome-panel:hover, html[data-motion="reduced"] .android-download-panel:hover,
html[data-motion="reduced"] .about-version-card:hover { transform: none; }
@media (prefers-reduced-motion: reduce), (update: slow) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  .button:hover, .welcome-panel:hover, .android-download-panel:hover, .about-version-card:hover { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar, html[data-theme="light"] .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg); }
}

/* Touch laptops/tablets and landscape phones also need non-zooming form text. */
@media (pointer: coarse) {
  .auth-card .form-stack input, .form-stack input, .form-stack textarea,
  .add-friend-form input, .chat-composer textarea, .theme-setting select,
  .user-search input, .user-delete-panel input { font-size: max(16px, 1rem); }
}


/* Same-origin GET pages retain their chrome instead of flashing through a reload.
   Unsupported WebViews ignore this block and keep ordinary navigation/short entries. */
@view-transition { navigation: auto; }
::view-transition { pointer-events: none; }
.topbar { view-transition-name: itcn-topbar; }
.mobile-dock { view-transition-name: itcn-dock; }
::view-transition-group(root) { animation-duration: 200ms; animation-timing-function: var(--ease-fluid); }
::view-transition-old(root) { animation: itcn-page-out 140ms ease-out both; mix-blend-mode: normal; }
::view-transition-new(root) { animation: itcn-page-in 200ms var(--ease-fluid) both; mix-blend-mode: normal; }
::view-transition-group(itcn-topbar), ::view-transition-group(itcn-dock) { animation-duration: 0s; }
::view-transition-old(itcn-topbar), ::view-transition-old(itcn-dock) { display: none; }
::view-transition-new(itcn-topbar), ::view-transition-new(itcn-dock) { animation: none; mix-blend-mode: normal; }
@keyframes itcn-page-out { to { opacity: 0; } }
@keyframes itcn-page-in { from { opacity: .6; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
html[data-navigation-fx="native"] .chat-thread .thread-heading,
html[data-navigation-fx="native"] .chat-thread .message-list { animation: none; }
html[data-motion="reduced"]::view-transition-group(*),
html[data-motion="reduced"]::view-transition-old(*),
html[data-motion="reduced"]::view-transition-new(*) { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
