:root {
  color-scheme: dark;
  --bg: #050706;
  --panel: rgba(9, 14, 13, 0.9);
  --panel-strong: rgba(14, 22, 20, 0.96);
  --text: #f0e2c4;
  --muted: #ad9b78;
  --gold: #d1aa58;
  --gold-bright: #f0d489;
  --line: rgba(209, 170, 88, 0.3);
  --green: #86cfaa;
  --red: #e48173;
  --blue: #61b8c6;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(209, 170, 88, 0.14), transparent 31rem),
    radial-gradient(circle at bottom right, rgba(36, 139, 135, 0.14), transparent 34rem),
    linear-gradient(145deg, #030504, #0b1110 52%, #040505);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border-radius: 999px;
  padding: 0 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 52px;
}

.dashboard-sidebar,
.hero-card,
.panel,
.state-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.dashboard-sidebar {
  position: sticky;
  top: 22px;
  align-self: start;
  min-height: calc(100vh - 44px);
  border-radius: 26px;
  padding: 20px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold-bright);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.muted,
.record-meta,
.empty-state {
  color: var(--muted);
}

.dashboard-nav {
  display: grid;
  gap: 8px;
  margin: 26px 0;
}

.dashboard-nav a {
  border: 1px solid rgba(209, 170, 88, 0.2);
  border-radius: 999px;
  color: var(--text);
  padding: 12px 14px;
  text-decoration: none;
}

.dashboard-nav a:hover,
.dashboard-nav a:focus-visible {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.language-link {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
}

.language-link:hover,
.language-link:focus-visible {
  color: var(--gold-bright);
}

.dashboard-main {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.hero-card,
.panel,
.state-card {
  border-radius: 24px;
  padding: clamp(18px, 3vw, 30px);
}

.hero-card {
  background:
    linear-gradient(135deg, rgba(209, 170, 88, 0.13), transparent 42%),
    linear-gradient(315deg, rgba(49, 139, 134, 0.1), transparent 40%),
    var(--panel-strong);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

h1 {
  max-width: 900px;
  color: var(--gold-bright);
  font-size: clamp(2.1rem, 6vw, 4.9rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
}

h3 {
  color: var(--gold-bright);
  font-size: 1.15rem;
}

.lede {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.7;
}

.hero-meta,
.button-row,
.panel-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.hero-meta span,
.status-pill {
  border: 1px solid rgba(209, 170, 88, 0.26);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  padding: 8px 12px;
}

#identity-label,
#session-label {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 10px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.content-stack,
.record-list {
  display: grid;
  gap: 12px;
}

.record-card,
.empty-state,
.shop-grid article,
.settings-grid label,
.settings-grid button {
  border: 1px solid rgba(209, 170, 88, 0.22);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.22);
  padding: 14px;
}

.record-card {
  display: grid;
  gap: 8px;
}

.record-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0;
  font-weight: 800;
}

.record-meta {
  display: grid;
  gap: 5px;
  margin: 0;
  line-height: 1.5;
}

#reading-history-meta {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.5;
}

#reading-history-renderer {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Saved text has no artwork to cross or position absolutely. Keep the generic
   renderer's canonical DOM and directional order in a container-safe grid. */
#reading-history-renderer .reading-layout {
  aspect-ratio: auto;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  grid-template-rows: none;
  min-height: 0;
}

#reading-history-renderer .reading-position {
  grid-area: auto;
  position: static;
  transform: none;
  width: auto;
}

.tag {
  border: 1px solid rgba(209, 170, 88, 0.3);
  border-radius: 999px;
  color: var(--gold);
  font-size: 0.75rem;
  padding: 3px 8px;
}

.tag.ok {
  color: var(--green);
}

.tag.info {
  color: var(--blue);
}

.state-card.warning {
  border-color: rgba(228, 129, 115, 0.4);
  color: #ffd3cd;
}

.state-card.success {
  border-color: rgba(134, 207, 170, 0.42);
  color: #d8ffe8;
}

.state-card.error {
  border-color: rgba(228, 129, 115, 0.7);
  color: #ffc7bf;
}

#backend-state {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.state-action {
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: inherit;
  padding: 9px 14px;
  text-decoration: none;
}

.availability-grid,
.credential-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.availability-grid p {
  margin: 0;
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 1px solid rgba(209, 170, 88, 0.5);
}

.primary-button {
  background: linear-gradient(135deg, var(--gold-bright), #9f7335);
  color: #080807;
  font-weight: 800;
}

.secondary-button,
.ghost-button {
  background: rgba(0, 0, 0, 0.2);
  color: var(--gold-bright);
}

.secondary-button.danger {
  color: var(--red);
}

.shop-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.settings-grid select {
  min-height: 42px;
  border: 1px solid rgba(209, 170, 88, 0.3);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  padding: 0 12px;
}

.checkbox-line {
  display: flex !important;
  flex-direction: row;
  align-items: center;
}

@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .dashboard-sidebar {
    position: static;
    min-height: auto;
  }

  .dashboard-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid,
  .shop-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .dashboard-shell {
    width: min(100% - 18px, 1480px);
    padding-top: 9px;
  }

  .dashboard-sidebar,
  .hero-card,
  .panel,
  .state-card {
    border-radius: 18px;
  }

  .dashboard-nav {
    grid-template-columns: 1fr;
  }

  .hero-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  #backend-state {
    align-items: stretch;
    flex-direction: column;
  }

  .state-action {
    text-align: center;
  }
}
