/*
 * Base tokens + chrome.
 * Values are taken from the accepted Flutter APK (lib/ui/original_chrome.dart,
 * lib/app.dart ThemeData) so the H5 build matches the Android surfaces 1:1.
 * Only viewport/safe-area handling is browser-specific.
 */

:root {
  --accent: #26a69a;
  --icon-muted: #707070;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --fg-secondary: rgba(0, 0, 0, 0.54);
  --fg-tertiary: #757575;
  --chip-bg: #f0f0f0;
  --cover-empty: #e8e8e8;
  --divider: rgba(0, 0, 0, 0.08);
  --surface-alt: #f7f7f7;
  --danger: #e53935;
  --app-bar-h: 56px;
  --bottom-nav-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --radius-card: 8px;
  --radius-feed: 6px;

  /* Material glyph paths, inlined so the reader chrome needs no extra requests. */
  --icon-heart-outline: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M16.5 3c-1.74 0-3.41.81-4.5 2.09C10.91 3.81 9.24 3 7.5 3 4.42 3 2 5.42 2 8.5c0 3.78 3.4 6.86 8.55 11.54L12 21.35l1.45-1.32C18.6 15.36 22 12.28 22 8.5 22 5.42 19.58 3 16.5 3zm-4.4 15.55l-.1.1-.1-.1C7.14 14.24 4 11.39 4 8.5 4 6.5 5.5 5 7.5 5c1.54 0 3.04.99 3.57 2.36h1.87C13.46 5.99 14.96 5 16.5 5c2 0 3.5 1.5 3.5 3.5 0 2.89-3.14 5.74-7.9 10.05z'/></svg>");
  --icon-heart-filled: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/></svg>");
  --icon-delete: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z'/></svg>");
  --icon-bookmark-outline: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17 3H7c-1.1 0-2 .9-2 2v16l7-3 7 3V5c0-1.1-.9-2-2-2zm0 15l-5-2.18L7 18V5h10v13z'/></svg>");
  --icon-bookmark-filled: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17 3H7c-1.1 0-2 .9-2 2v16l7-3 7 3V5c0-1.1-.9-2-2-2z'/></svg>");
  --icon-skip-previous: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 6h2v12H6zm3.5 6l8.5 6V6z'/></svg>");
  --icon-skip-next: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z'/></svg>");
}

[data-theme='dark'] {
  --bg: #121212;
  --fg: #ececec;
  --fg-secondary: rgba(255, 255, 255, 0.66);
  --fg-tertiary: #9e9e9e;
  --chip-bg: #262626;
  --cover-empty: #2a2a2a;
  --divider: rgba(255, 255, 255, 0.12);
  --surface-alt: #1c1c1c;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.35;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

body.reader-active {
  background: #000;
  overflow: hidden;
  height: 100%;
}

img {
  border-style: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

h1,
h2,
h3,
p,
ol,
ul {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.page-host {
  display: block;
  min-height: 100vh;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

body.no-bottom-nav .page-host {
  padding-bottom: var(--safe-bottom);
}

body[data-route='reader'] .page-host {
  padding-bottom: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.page {
  min-height: 100vh;
}

/* ---------- app bar ---------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  height: calc(var(--app-bar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg);
}

.app-bar--dark {
  background: #000;
  color: #fff;
}

.app-bar__title {
  font-size: 22px;
  font-weight: 400;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.app-bar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding-right: 4px;
}

.app-bar__spacer {
  display: block;
}

.app-bar__back,
.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  position: relative;
}

.app-bar__back::before {
  content: '';
  width: 11px;
  height: 11px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.app-bar__back--light,
.icon-btn--light {
  color: #fff;
}

.icon-btn--list::before {
  content: '';
  width: 18px;
  height: 14px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  box-shadow: inset 0 0 0 2px transparent;
  background: linear-gradient(currentColor, currentColor) center/100% 2px no-repeat;
}

.icon-btn--sweep::before {
  content: '';
  width: 16px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-width: 5px;
  border-radius: 0 0 3px 3px;
}

.icon-btn--star::before {
  content: '★';
  font-size: 20px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.6);
}

.icon-btn--star.is-active::before {
  color: #ffc107;
}

/* ---------- bottom nav ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--icon-muted);
}

.bottom-nav__item--active {
  color: var(--accent);
}

.bottom-nav__label {
  font-size: 12px;
  line-height: 1;
}

.mask-icon {
  display: block;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-position: center;
  mask-size: contain;
  -webkit-mask-size: contain;
}

/* ---------- spinner / loading ---------- */

.spinner {
  display: inline-block;
  border-style: solid;
  border-color: rgba(38, 166, 154, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.center-fill {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 48px 0;
}

.load-more {
  display: grid;
  place-items: center;
  padding: 16px 0 24px;
}

/* ---------- toast ---------- */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 84%;
  padding: 10px 16px;
  border-radius: 4px;
  background: #323232;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- bottom sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
}

.sheet__mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.sheet__panel {
  position: relative;
  width: 100%;
  max-height: 72vh;
  overflow: auto;
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-radius: 16px 16px 0 0;
}

.sheet__title {
  position: sticky;
  top: 0;
  padding: 16px;
  background: var(--bg);
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--divider);
}

.sheet__list {
  padding: 4px 0 8px;
}

.sheet__row {
  display: block;
  width: 100%;
  padding: 13px 16px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--divider);
}

.sheet__row--active {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  font-size: 14px;
  color: var(--accent);
}

.btn--filled {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn--filled[disabled] {
  background: rgba(0, 0, 0, 0.12);
  color: rgba(0, 0, 0, 0.38);
}

.btn--text {
  padding: 0 8px;
  min-height: 32px;
}

.btn--danger {
  color: var(--danger);
}

/* ---------- alert dialog ---------- */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.dialog__mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.dialog__panel {
  position: relative;
  width: 100%;
  max-width: 320px;
  padding: 20px 24px 8px;
  border-radius: 28px;
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.dialog__title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 500;
}

.dialog__message {
  margin: 0;
  font-size: 14px;
  color: var(--fg-secondary);
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 0 8px;
}

/* Dismissible parity: the red delete track shows while the row slides away. */
.swipe--active {
  position: relative;
  z-index: 1;
}
