:root {
  color-scheme: dark;
  font-family: "Montserrat", Arial, sans-serif;
  background: #080b1a;
  color: #f7f4ff;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --panel: rgba(11, 15, 37, 0.88);
  --border: rgba(196, 181, 253, 0.22);
  --muted: #c5c4d6;
  --accent: #c4b5fd;
  --accent-strong: #8b75df;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: #080b1a;
  background-image:
    linear-gradient(rgba(8, 11, 26, 0.32), rgba(8, 11, 26, 0.52)),
    url("/images/starry-story-background.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.page-shell {
  width: min(1180px, 100% - 40px);
  margin: 0 auto;
}

.site-header {
  padding: 28px 0 24px;
}

.banner {
  display: block;
  width: 100%;
  height: clamp(170px, 26vw, 300px);
  border: 1px solid var(--border);
  border-radius: 16px;
  object-fit: cover;
  object-position: center 44%;
}

.brand {
  padding: 18px 4px 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
}

.brand p {
  margin-bottom: 0;
  color: var(--muted);
}

main {
  padding-bottom: 28px;
}

.panel {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 1.3rem;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.account-panel {
  margin-bottom: 20px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.status,
.muted {
  color: var(--muted);
  line-height: 1.65;
}

.status:empty {
  display: none;
}

.status[data-kind="error"] {
  color: #ffb4b4;
}

.status[data-kind="success"] {
  color: #a8f0c6;
}

.account-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 12px;
}

label {
  display: grid;
  gap: 8px;
  color: #e6e1f6;
  font-size: 0.88rem;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid rgba(196, 181, 253, 0.28);
  border-radius: 8px;
  outline: none;
  background: rgba(5, 8, 23, 0.84);
  color: #fff;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

.account-actions {
  display: flex;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent-strong);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.button:hover {
  background: #7560c9;
}

.button-secondary,
.button-quiet {
  border-color: rgba(196, 181, 253, 0.4);
  background: transparent;
}

.button-google {
  border-color: #d5d9e2;
  background: #f7f8fa;
  color: #20242c;
}

.button-google:hover {
  background: #e6e9ef;
}

.button-secondary:hover,
.button-quiet:hover {
  background: rgba(196, 181, 253, 0.12);
}

.library-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.72fr) minmax(0, 2fr);
  align-items: start;
  gap: 20px;
}

.library-panel {
  position: sticky;
  top: 18px;
}

.novel-list {
  display: grid;
  gap: 10px;
}

.novel-button {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  color: #fff;
  text-align: left;
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 180ms ease, border-color 180ms ease;
}

@media (hover: hover) {
  .novel-button:hover {
    transform: translateY(-2px);
  }
}

.novel-button:active {
  transform: translateY(0) scale(0.98);
}

@media (prefers-reduced-motion: reduce) {
  .novel-button {
    transition: none;
  }

  .novel-button:hover,
  .novel-button:active {
    transform: none;
  }
}

.novel-button:hover,
.novel-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(139, 117, 223, 0.2);
}

.novel-button strong,
.novel-button span {
  display: block;
}

.novel-button span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.83rem;
}

.reader-column {
  display: grid;
  gap: 20px;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 22px;
}

.reader-toolbar label {
  flex: 0 0 auto;
}

.chapter-text {
  max-width: 72ch;
  margin: 0 auto;
  color: #f0edf7;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  line-height: 1.9;
}

.chapter-text h3 {
  margin-bottom: 1.5rem;
  color: #fff;
  font-family: "Montserrat", Arial, sans-serif;
  font-size: 1.3rem;
  line-height: 1.4;
}

.chapter-text p {
  white-space: pre-wrap;
}

.progress-form,
.comment-form {
  display: grid;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.progress-form .button,
.comment-form .button {
  justify-self: start;
}

.comment-list {
  display: grid;
  gap: 12px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.comment-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
}

.comment-body {
  margin: 0;
  color: #f0edf7;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

footer {
  padding: 4px 0 28px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 28px, 600px);
  }

  .account-form,
  .library-layout {
    grid-template-columns: 1fr;
  }

  .library-panel {
    position: static;
  }
}

@media (max-width: 480px) {
  .page-shell {
    width: min(100% - 20px, 600px);
  }

  .panel {
    padding: 17px;
  }

  .account-actions {
    flex-wrap: wrap;
  }

  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}

.uploaded-story {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30%;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  text-decoration: none;
}

.story-shell {
  max-width: 900px;
  padding-top: 28px;
  padding-bottom: 40px;
}

.story-shell header {
  margin: 32px 0 24px;
}

.story-navigation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.story-card-copy {
  min-width: 0;
  overflow-wrap: anywhere;
}

.story-card-cover {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 6px;
}

.story-cover {
  margin: 0 auto 28px;
  max-width: 300px;
}

.story-cover img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* A quiet, tactile rhythm for the standalone story reader. */
.story-shell .button,
.story-shell select {
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1),
    background-color 180ms ease, border-color 180ms ease;
}

@media (hover: hover) {
  .story-shell .button:not(:disabled):hover {
    transform: translateY(-2px);
  }
}

.story-shell .button:not(:disabled):active {
  transform: translateY(0) scale(0.97);
}

@media (prefers-reduced-motion: reduce) {
  .story-shell .button,
  .story-shell select {
    transition: none;
  }

  .story-shell .button:not(:disabled):hover,
  .story-shell .button:not(:disabled):active {
    transform: none;
  }
}

.public-site-link {
  color: var(--accent);
  text-underline-offset: 3px;
}

.chapter-discussion {
  max-width: 72ch;
  margin: 40px auto 28px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}
.chapter-discussion h2 { margin-bottom: 12px; }
.chapter-discussion .comment-form { border-top: 0; padding-top: 0; }
.chapter-discussion input,
.chapter-discussion textarea { width: 100%; min-width: 0; }
.chapter-discussion textarea { resize: vertical; }
.chapter-discussion .comment-meta strong { overflow-wrap: anywhere; }
.chapter-discussion [hidden] { display: none; }
