/*
| Application shell: top bar, Stories/Books tabs, entry cards and forms.
| Mobile-first; the desktop overrides live at the bottom.
*/

:root {
  --appbar-h: 52px;
  --tabbar-h: 58px;
  --ink: #fff;
  --line: rgba(255, 255, 255, .32);
  --panel: rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body {
  height: auto;
  min-height: 100%;
}

body {
  color: var(--ink);
  background-color: #220052;
  background-image: none;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  padding-top: calc(var(--appbar-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

/*
| The background sits on a fixed pseudo-element rather than using
| background-attachment: fixed, which stutters badly on iOS Safari.
*/
body::before {
  content: "";
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: url("/bg-jie.jpg") center / cover no-repeat;
  z-index: -1;
}

/*
| Top bar --------------------------------------------------------------
|
| The inset is 0 while a browser toolbar is in the way and only grows once
| the app is installed, where the page runs under the status bar. Without it
| the logo would sit behind the clock.
*/
.app-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  height: calc(var(--appbar-h) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 12px 0 16px;
  background: rgba(34, 0, 82, .72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-mark {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.app-bar-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--ink);
  opacity: .75;
  text-decoration: none;
}

.app-bar-action:hover { opacity: 1; color: var(--ink); }

/* Tabs ---------------------------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(34, 0, 82, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ink);
  opacity: .5;
  text-decoration: none;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.tab:hover { color: var(--ink); text-decoration: none; opacity: .8; }
.tab.is-active { opacity: 1; }
.tab svg { display: block; }

/* Content -------------------------------------------------------------- */
.main {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.section-title {
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  opacity: .6;
  margin: 26px 0 10px;
}

/* Love block ----------------------------------------------------------- */
.love { text-align: center; margin-bottom: 22px; }

.love-img {
  width: 100%;
  max-width: 320px;
  /* A fixed pixel height overflowed narrow screens; cap by viewport instead */
  max-height: 38vh;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.love-message {
  margin: 12px auto 0;
  max-width: 34em;
  font-size: 14px;
  line-height: 1.5;
  opacity: .85;
}

/* Entries -------------------------------------------------------------- */
.entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.entry-title {
  font-size: 15px;
  letter-spacing: .06em;
  margin: 0 0 8px;
  opacity: .85;
}

/* Search --------------------------------------------------------------- */
.search-form { margin-bottom: 4px; }

.search-note {
  margin: -4px 0 12px;
  font-size: 12px;
  opacity: .6;
}

/* The searched words inside a result */
mark {
  background: rgba(255, 214, 0, .3);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

/* Marks a result as coming from the stories or the books list */
.entry-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.entry-head .entry-title { margin: 0; }

.entry-type {
  flex: none;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  opacity: .7;
}

/* Small dimmed line under a title, e.g. the day a book was added */
.entry-meta {
  margin: -4px 0 8px;
  font-size: 12px;
  letter-spacing: .04em;
  opacity: .55;
}

.entry-body {
  margin: 0;
  line-height: 1.6;
  /* Long pasted words must not force the page to scroll sideways */
  overflow-wrap: anywhere;
}

.nowhitespace { white-space: pre-wrap; }

.entry-actions { margin-top: 12px; }

.empty {
  opacity: .6;
  text-align: center;
  padding: 28px 8px;
}

/* "See more" / "See all" under a truncated list */
.list-more {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 4px 0 8px;
}

/* While the next rows are on their way, the buttons stop responding */
.list-more.is-loading .btn {
  opacity: .45;
  pointer-events: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner[hidden] { display: none; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Respect the system setting: no endless rotation, just a steady marker */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; opacity: .6; }
}

/* Base controls --------------------------------------------------------- */
/*
| These used to come from the Bootstrap CDN bundle. They are defined locally
| now so the app ships no external stylesheet: one less request on mobile and
| nothing to break if the CDN is unreachable.
*/
.form-control {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  line-height: 1.5;
}

.form-control:focus { outline: none; }

textarea.form-control { resize: vertical; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  font: inherit;
  text-align: center;
  text-decoration: none;
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn:hover { text-decoration: none; }

.btn-block { display: block; width: 100%; }

.btn-outline-light { color: var(--ink); background: rgba(255, 255, 255, .06); }
.btn-outline-light:hover { background: rgba(255, 255, 255, .16); color: var(--ink); }

.btn-primary {
  color: #220052;
  background: #fff;
  border-color: #fff;
  font-weight: 500;
}

.btn-primary:hover { color: #220052; background: #ece7f5; }

/* Forms ---------------------------------------------------------------- */
.form-group { margin-bottom: 12px; }

.form-control {
  background-color: rgba(255, 255, 255, .08);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  min-height: 46px;
  /* 16px keeps iOS from zooming the page in when a field takes focus */
  font-size: 16px;
}

.form-control:focus {
  background-color: rgba(255, 255, 255, .14);
  border-color: #fff;
  color: var(--ink);
  box-shadow: none;
}

.form-control::placeholder { color: rgba(255, 255, 255, .5); }

textarea.form-control { line-height: 1.55; }

input[type="date"].form-control { -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .7; }

.btn {
  border-radius: 10px;
  min-height: 46px;
  font-size: 15px;
  letter-spacing: .04em;
}

.btn-outline-light { border-color: var(--line); }

.btn-sm { min-height: 38px; font-size: 13px; padding: 6px 16px; }

.btn + .btn { margin-top: 8px; }

/* Secondary action next to a primary one (e.g. Cancel beside Save) */
.btn-quiet {
  color: var(--ink);
  opacity: .6;
}

.btn-quiet:hover { color: var(--ink); opacity: 1; }

/* Desktop: fold the tabs up into the top bar --------------------------- */
@media (min-width: 768px) {
  body { padding-bottom: 28px; }

  /* Sit the tabs inside the top bar rather than along the bottom edge */
  .tabbar {
    top: 0;
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    z-index: 21;
    height: var(--appbar-h);
    align-items: center;
    padding-bottom: 0;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: none;
    gap: 8px;
  }

  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 8px;
    height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 12px;
  }

  .tab svg { width: 16px; height: 16px; }

  .tab.is-active { background: rgba(255, 255, 255, .14); }
}

/* Flash messages -------------------------------------------------------- */
.flash {
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  border: 1px solid var(--line);
}

.flash-ok { background: rgba(80, 200, 130, .18); }
.flash-error { background: rgba(230, 90, 110, .22); }

/* The logout control is a form button, so reset the button chrome */
.app-bar-form { margin: 0; display: flex; }

button.app-bar-action {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Login page ------------------------------------------------------------ */
.auth-main {
  max-width: 420px;
  margin: 0 auto;
  padding: 12vh 16px 32px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 20px;
}


body.auth-body { padding-top: 0; padding-bottom: 0; }

/* Error pages (404, 500) ------------------------------------------------- */
.error-card { text-align: center; }

.error-title {
  font-size: 18px;
  letter-spacing: .02em;
  margin: 4px 0 6px;
}

.error-text {
  font-size: 14px;
  opacity: .65;
  margin-bottom: 20px;
}

/* Google sign-in page --------------------------------------------------- */
/*
| The source artwork is black line art on transparency, which would vanish on
| this dark card. The ink is recoloured to white in the asset itself rather
| than with a CSS invert() filter — a filter also flips the heart's hue, and
| inverting back via hue-rotate() only approximates, which washed the red out
| to salmon.
*/
.auth-mark {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0 auto 18px;
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.auth-note {
  margin-top: 16px;
  font-size: 12px;
  text-align: center;
  opacity: .55;
}
