:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-alt: #efece4;
  --text: #1c1b18;
  --text-muted: #5f5b52;
  --border: #dcd7cc;
  --primary: #2d5a4c;
  --primary-hover: #21453a;
  --primary-soft: #e6efe9;
  --accent: #b85d38;
  --danger: #c53030;
  --danger-bg: #fde8e8;
  --success: #188038;
  --highlight-bg: #fff3b0;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(28, 27, 24, 0.06);
  --font-sans: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Noto Serif KR', Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header & Main Nav */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--primary);
  cursor: pointer;
}

.brand-badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-weight: 700;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.plan-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.plan-pill.standard {
  background: #e8f0fe;
  color: #1967d2;
  border-color: #c2d7fa;
}

.plan-pill.premium {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

/* Main Container */
.main-container {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  flex: 1;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Cards & Buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.section-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-danger {
  color: var(--danger);
  border-color: #f5c2c2;
  background: #fff5f5;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.84rem;
}

/* Forms & Validation (modern-web-guidance) */
.field {
  margin-bottom: 1.1rem;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.92rem;
}

.hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
}

.rules-list {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 0.2rem 0 0.45rem 1.2rem;
  padding: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #9ca3af;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background-color: var(--danger-bg);
}

:is(input, select, textarea):is(:user-valid, .user-valid-fallback) {
  border-color: var(--success);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.84rem;
  margin-top: 0.3rem;
}

:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) + .error-msg {
  display: block;
}

.field:has(input:user-invalid) .rules-list {
  color: var(--danger);
  font-weight: 600;
}

.field:has(input:user-valid) .rules-list {
  color: var(--success);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-row > input {
  flex: 1;
}

/* Library & Document Viewer */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1rem;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.doc-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.doc-type-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
}

.doc-preview {
  font-size: 0.86rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

/* Hero Banner (Full-bleed illustration with left-side overlay text) */
.hero-banner {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  background: #faf7f0;
  min-height: 400px;
  display: flex;
  align-items: center;
}

.hero-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: right center;
  z-index: 0;
}

.hero-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(250, 247, 240, 0.94) 0%,
    rgba(250, 247, 240, 0.82) 42%,
    rgba(250, 247, 240, 0.05) 66%,
    rgba(250, 247, 240, 0) 100%
  );
  z-index: 1;
  pointer-events: none;
}

.hero-copy {
  position: relative;
  z-index: 2;
  padding: 2.5rem 2.75rem;
  max-width: 540px;
}

.hero-eyebrow {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.85rem;
}

.hero-title {
  margin: 0 0 0.7rem 0;
  font-size: 1.9rem;
  line-height: 1.3;
  font-weight: 800;
  color: var(--text);
}

.hero-desc {
  margin: 0 0 1.35rem 0;
  font-size: 0.96rem;
  color: var(--text-muted);
  max-width: 42ch;
}

.hero-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  .hero-banner {
    min-height: 320px;
    align-items: flex-end;
  }
  .hero-banner::after {
    background: linear-gradient(
      0deg,
      rgba(250, 247, 240, 0.96) 0%,
      rgba(250, 247, 240, 0.86) 55%,
      rgba(250, 247, 240, 0.15) 100%
    );
  }
  .hero-copy {
    padding: 1.5rem;
    max-width: 100%;
  }
  .hero-title {
    font-size: 1.45rem;
  }
}

/* Bookshelf Library (5 columns desktop, 3 columns smaller screens) */
.bookshelf-wall {
  background: linear-gradient(180deg, #6e4f37 0%, #583e2a 100%);
  border: 10px solid #4a3322;
  border-radius: 14px;
  padding: 1.25rem 1.25rem 0.75rem;
  box-shadow: inset 0 8px 24px rgba(0, 0, 0, 0.35), var(--shadow);
}

.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1.5rem 1rem;
}

@media (max-width: 900px) {
  .bookshelf-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.shelf-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-height: 210px;
  padding: 0.85rem 0.5rem 1.15rem;
  background: rgba(30, 20, 12, 0.28);
  border-radius: 8px 8px 0 0;
  border-bottom: 14px solid #8c6445;
  box-shadow: 0 6px 0 #3f2b1c, inset 0 4px 10px rgba(0, 0, 0, 0.28);
}

.shelf-slot.empty-slot {
  opacity: 0.45;
}

.book-item {
  width: 100%;
  max-width: 138px;
  height: 174px;
  border-radius: 4px 10px 10px 4px;
  background: linear-gradient(135deg, #2d5a4c 0%, #1f4036 100%);
  border-left: 8px solid #163028;
  box-shadow: 4px 6px 14px rgba(0, 0, 0, 0.38);
  padding: 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  text-align: left;
}

.book-item[data-type="PDF"] {
  background: linear-gradient(135deg, #9b3d2c 0%, #732a1d 100%);
  border-left-color: #541d14;
}

.book-item[data-type="DOCX"] {
  background: linear-gradient(135deg, #2b547e 0%, #1c3a59 100%);
  border-left-color: #13283f;
}

.book-item[data-type="HWP"],
.book-item[data-type="HWPX"] {
  background: linear-gradient(135deg, #3b6978 0%, #204051 100%);
  border-left-color: #142a36;
}

.book-item:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 6px 12px 20px rgba(0, 0, 0, 0.48);
}

.book-badge {
  align-self: flex-start;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  letter-spacing: 0.03em;
}

.book-title {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.book-meta {
  font-size: 0.7rem;
  opacity: 0.82;
}

/* Upload Dropzone */
.upload-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* Open-Book Single-Page Fixed-Frame Viewer */
.book-viewer-shell {
  height: calc(100vh - 102px);
  min-height: 540px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.viewer-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.book-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, #e9e3d5 0%, #ded6c4 100%);
  overflow: hidden;
}

.page-turn-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(28, 27, 24, 0.12);
  transition: transform 0.12s, background 0.12s;
}

.page-turn-btn:hover:not(:disabled) {
  background: #fff;
  transform: scale(1.06);
}

.page-turn-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.book-page-frame {
  height: 100%;
  width: min(740px, 100%);
  background: #fffdf8;
  border-radius: 4px 14px 14px 4px;
  border: 1px solid #d4cbb8;
  box-shadow:
    inset 18px 0 28px -18px rgba(60, 45, 25, 0.22),
    6px 12px 30px rgba(28, 27, 24, 0.16);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.book-page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem 2.1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rich-book-content {
  width: 100%;
  font-family: var(--font-serif);
  font-size: 1.02rem;
  line-height: 1.85;
  color: var(--text);
}

.rich-book-content p {
  margin: 0 0 0.9rem 0;
}

.rich-book-content h1,
.rich-book-content h2,
.rich-book-content h3 {
  margin: 0.6rem 0 0.7rem 0;
  line-height: 1.35;
}

.rich-book-content img,
.rich-book-content .doc-img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 0.65rem auto;
  display: block;
}

.rich-book-content table,
.rich-book-content .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.rich-book-content th,
.rich-book-content td {
  border: 1px solid #cfc7b6;
  padding: 0.45rem 0.6rem;
  background: #fff;
}

.pdf-page-stage {
  position: relative;
  margin: auto;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  background: #fff;
}

.pdf-page-canvas {
  display: block;
}

.pdf-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.pdf-text-span {
  position: absolute;
  color: transparent;
  white-space: pre;
  line-height: 1;
  border-radius: 3px;
}

.pdf-text-span.active-reading {
  background: rgba(250, 204, 21, 0.48);
  box-shadow: 0 0 0 1px rgba(234, 179, 8, 0.7);
}

.book-page-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-top: 1px solid rgba(212, 203, 184, 0.5);
  background: #fbf8f0;
}

.viewer-bottom-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.page-counter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.reader-sentence {
  display: inline;
  padding: 0.1rem 0.15rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.reader-sentence:hover {
  background: var(--surface-alt);
}

.reader-sentence.active-reading {
  background: var(--highlight-bg);
  box-shadow: 0 0 0 2px #facc15;
}

.tts-player-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  background: var(--primary-soft);
  border: 1px solid #9bc4ac;
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
}

@media (max-width: 720px) {
  .book-stage {
    padding: 0.6rem;
    gap: 0.35rem;
  }
  .page-turn-btn {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }
  .book-page-body {
    padding: 1rem 1.1rem;
  }
}

/* Tabs */
.sub-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.sub-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.sub-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Pricing Grid */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
}

.plan-card.current {
  border: 2px solid var(--primary);
  box-shadow: var(--shadow);
}

.plan-price {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--primary);
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.92rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 700;
  background: var(--surface-alt);
}

/* Auth Grid */
.auth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
}

/* Native Dialog Styling (modern-web-guidance) */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(28, 27, 24, 0.52);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.dialog-header h1,
.dialog-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* Toast / Status */
.toast-banner {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #1c1b18;
  color: #fff;
  padding: 0.75rem 1.15rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 100;
  display: none;
}

.toast-banner.show {
  display: block;
}

.toast-banner.error {
  background: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.correction-inline-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.6rem;
  align-items: end;
}

@media (max-width: 680px) {
  .correction-inline-form {
    grid-template-columns: 1fr;
  }
}
