:root {
  color-scheme: light;
  --ink: #153f38;
  --ink-soft: #4a655f;
  --paper: #f4efe5;
  --paper-light: #fffdf7;
  --accent: #e96f51;
  --accent-dark: #bd4934;
  --line: rgba(21, 63, 56, 0.18);
  --shadow: 0 24px 70px rgba(37, 52, 44, 0.12);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 3%, rgba(233, 111, 81, 0.17), transparent 28rem),
    linear-gradient(180deg, #f7f2e8 0%, var(--paper) 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 430px);
  border: 1px solid rgba(21, 63, 56, 0.12);
  border-radius: 30px;
  padding: clamp(28px, 8vw, 46px);
  background: rgba(255, 253, 247, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-brand {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 38px;
  place-items: center;
  border-radius: 50% 50% 46% 54%;
  color: var(--paper-light);
  background: var(--ink);
  font-family: Georgia, serif;
  font-size: 25px;
}

.login-card h1 {
  font-size: clamp(32px, 8.5vw, 44px);
  line-height: 1;
  white-space: nowrap;
}

.login-intro {
  margin: 18px 0 28px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.login-form input { padding: 0 15px; }
.login-message {
  margin: 8px 0 0;
  border: 1px solid rgba(189, 73, 52, 0.22);
  border-radius: 12px;
  padding: 11px 13px;
  color: var(--accent-dark);
  background: rgba(233, 111, 81, 0.08);
  font-size: 12px;
  line-height: 1.45;
}

.login-message:empty { display: none; }

.password-field { position: relative; }
.password-field input { padding-right: 56px; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  width: 40px;
  height: 40px;
  transform: translateY(-50%);
  place-items: center;
  border: 0;
  border-radius: 11px;
  color: var(--ink-soft);
  background: transparent;
}

.password-toggle:hover { background: rgba(21, 63, 56, 0.06); }
.password-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.password-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.password-toggle .eye-closed { display: none; }
.password-toggle[aria-pressed="true"] .eye-open { display: none; }
.password-toggle[aria-pressed="true"] .eye-closed { display: block; }

.shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(48px, env(safe-area-inset-bottom));
}

.hero { padding: 14px 2px 42px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 54px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.profile-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 12px 4px 5px;
  color: var(--ink);
  background: rgba(255, 253, 247, 0.72);
  font-size: 12px;
  font-weight: 750;
}

.profile-button > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-avatar,
.settings-avatar {
  display: grid;
  overflow: hidden;
  place-items: center;
  border-radius: 50%;
  background: var(--paper-light);
}

.profile-avatar { width: 32px; height: 32px; font-size: 17px; }
.profile-avatar img,
.settings-avatar img,
.folder-avatar img { width: 100%; height: 100%; object-fit: cover; }

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50% 50% 46% 54%;
  color: var(--paper-light);
  background: var(--ink);
  font-family: Georgia, serif;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 650px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(48px, 11vw, 84px);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.94;
}

h1 em { color: var(--accent); font-weight: 500; }

.intro {
  max-width: 440px;
  margin: 24px 0 0;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.55;
}

.create-panel, .library {
  border: 1px solid rgba(21, 63, 56, 0.12);
  border-radius: 26px;
  background: rgba(255, 253, 247, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.create-panel { padding: 26px; }
.library { margin-top: 18px; padding: 26px; }

.section-heading {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
  margin-bottom: 26px;
}

.section-heading h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.4;
}

form { display: grid; gap: 10px; }

label {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  color: var(--ink);
  background: var(--paper-light);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input { padding: 0 94px 0 15px; }

select {
  appearance: none;
  padding: 0 44px 0 15px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 20px) 23px, calc(100% - 15px) 23px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(233, 111, 81, 0.12);
}

.url-row { position: relative; }

.source-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 5px;
  border-radius: 13px;
  padding: 4px;
  background: #e8e7dd;
}

.source-mode-button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}

.source-mode-button.is-active {
  color: var(--ink);
  background: var(--paper-light);
  box-shadow: 0 2px 8px rgba(21, 63, 56, 0.1);
}

.form-fields {
  display: grid;
  gap: 10px;
}

.form-fields[hidden] { display: none; }

textarea {
  min-height: 220px;
  resize: vertical;
  padding: 14px 15px;
  line-height: 1.5;
}

.paste-button {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  padding: 0 12px;
  color: var(--ink);
  background: #e8e7dd;
  font-size: 12px;
  font-weight: 750;
}

.primary-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 58px;
  margin-top: 12px;
  border: 0;
  border-radius: 15px;
  padding: 0 19px;
  color: white;
  background: var(--ink);
  font-weight: 780;
  box-shadow: 0 14px 26px rgba(21, 63, 56, 0.2);
  transition: transform 160ms ease, background 160ms ease;
}

.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { cursor: wait; opacity: 0.65; }

.form-message {
  min-height: 19px;
  margin: 12px 0 -4px;
  color: var(--accent-dark);
  font-size: 13px;
}

.library-heading {
  grid-template-columns: 1fr auto;
  margin-bottom: 20px;
}

.library-actions { display: flex; gap: 8px; }

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
  font-size: 20px;
}

.folder-list { display: grid; gap: 14px; }

.library-folder {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(244, 239, 229, 0.58);
}

.library-folder > summary {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 76px;
  padding: 13px 16px;
  cursor: pointer;
  list-style: none;
}

.library-folder > summary::-webkit-details-marker { display: none; }

.folder-avatar {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(21, 63, 56, 0.12);
  border-radius: 16px;
  background: var(--paper-light);
  font-size: 25px;
  box-shadow: 0 7px 18px rgba(21, 63, 56, 0.08);
}

.folder-heading { display: grid; gap: 3px; min-width: 0; }

.folder-name {
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-summary { color: var(--ink-soft); font-size: 11px; }

.folder-chevron {
  color: var(--ink-soft);
  font-size: 20px;
  transition: transform 160ms ease;
}

.library-folder[open] .folder-chevron { transform: rotate(180deg); }

.folder-books {
  display: grid;
  gap: 10px;
  padding: 0 10px 10px;
}

.folder-empty {
  margin: 0;
  padding: 2px 16px 18px 76px;
  color: var(--ink-soft);
  font-size: 12px;
}

.book-card {
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper-light);
}

.settings-dialog {
  width: min(calc(100% - 28px), 620px);
  max-height: min(84vh, 760px);
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 26px;
  color: var(--ink);
  background: var(--paper-light);
  box-shadow: 0 30px 100px rgba(21, 63, 56, 0.28);
}

.settings-dialog::backdrop {
  background: rgba(21, 40, 36, 0.48);
  backdrop-filter: blur(4px);
}

.settings-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}

.settings-header .eyebrow { margin-bottom: 6px; }

.settings-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-weight: 500;
}

.settings-header p:last-child { margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }

.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
  border-radius: 18px;
  padding: 14px;
  background: var(--paper);
}

.settings-avatar { width: 52px; height: 52px; font-size: 27px; }
.profile-card > div { display: grid; gap: 3px; }
.profile-card strong { font-family: Georgia, serif; font-size: 20px; font-weight: 500; }
.profile-card span { color: var(--ink-soft); font-size: 11px; }

.settings-section {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 21px;
}

.settings-section h3 { margin: 0; font-family: Georgia, serif; font-size: 20px; font-weight: 500; }
.settings-section > p { margin: 6px 0 14px; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }

.avatar-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.avatar-option {
  display: grid;
  min-height: 58px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--paper-light);
  font-size: 27px;
}

.avatar-option[aria-checked="true"] {
  border-color: var(--accent);
  background: rgba(233, 111, 81, 0.1);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.avatar-option:disabled { cursor: wait; opacity: 0.6; }

.avatar-upload-button {
  display: inline-flex;
  min-height: 42px;
  margin: 0 0 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--paper-light);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.share-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.share-form input { padding: 0 14px; }

.share-form button {
  border: 0;
  border-radius: 14px;
  padding: 0 16px;
  color: white;
  background: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.share-form button:disabled { cursor: wait; opacity: 0.6; }

.settings-message { min-height: 18px; margin: 9px 0 0; color: var(--accent-dark); font-size: 11px; }

.shared-users { display: grid; gap: 7px; margin: 8px 0 0; padding: 0; list-style: none; }

.shared-users li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--paper);
  font-size: 12px;
}

.shared-users button {
  border: 0;
  padding: 0;
  color: var(--accent-dark);
  background: transparent;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.shared-users-empty { color: var(--ink-soft); }

.logout-button {
  width: 100%;
  min-height: 48px;
  margin-top: 26px;
  border: 1px solid rgba(189, 73, 52, 0.3);
  border-radius: 14px;
  color: var(--accent-dark);
  background: rgba(233, 111, 81, 0.06);
  font-size: 12px;
  font-weight: 750;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.book-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.book-status {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-date { color: var(--ink-soft); font-size: 11px; }

.book-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.book-delete {
  border: 0;
  padding: 4px 0;
  color: var(--accent-dark);
  background: transparent;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.book-delete:disabled { cursor: wait; opacity: 0.6; }

.book-title {
  margin: 13px 0 5px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.book-source {
  display: block;
  overflow: hidden;
  margin-bottom: 16px;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  overflow: hidden;
  height: 5px;
  border-radius: 99px;
  background: #e7e4d9;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 400ms ease;
}

.book-meta {
  margin-top: 9px;
  color: var(--ink-soft);
  font-size: 11px;
}

.book-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}

.book-text-link,
.book-retry {
  border: 0;
  padding: 0;
  color: var(--accent-dark);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.book-retry:disabled { cursor: wait; opacity: 0.6; }

.book-audio { width: 100%; margin-top: 14px; }

.book-error {
  margin: 12px 0 0;
  color: #9d3b2c;
  font-size: 12px;
  line-height: 1.45;
}

.empty-state {
  padding: 32px 16px 18px;
  text-align: center;
}

.empty-state > span {
  display: grid;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 50%;
  color: var(--paper-light);
  background: var(--accent);
  font-family: Georgia, serif;
  font-size: 23px;
}

.empty-state h3 { margin: 0; font-family: Georgia, serif; font-weight: 500; }
.empty-state p { margin: 8px auto 0; max-width: 330px; color: var(--ink-soft); font-size: 13px; line-height: 1.5; }

@media (min-width: 680px) {
  .shell { padding-inline: 30px; }
  .create-panel, .library { padding: 32px; }
}

@media (max-width: 420px) {
  .settings-dialog { padding: 21px; }
  .share-form { grid-template-columns: 1fr; }
  .share-form button { min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
