/* CSS Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Custom Properties */
:root {
  --bg: #FDF6EC;
  --text: #4A3520;
  --accent: #C4A67A;
  --border: #E8D5B8;
  --input-bg: #FFF8EE;
  --input-border: #D4C4A8;
  --highlight-word: #FFE066;
  --highlight-sentence: #C8E6FF;
}

/* Base */
body {
  background: var(--bg);
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--text);
}

#app {
  max-width: 768px;
  margin: 0 auto;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--border);
}

.header.header-sticky {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
  transition: transform 250ms ease;
}

.header.header-hidden {
  transform: translateY(-100%);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-right {
  justify-content: flex-end;
}

.header-center {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.header a,
.header button {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  text-decoration: none;
}

.header svg {
  width: 20px;
  height: 20px;
  stroke: var(--accent);
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-title {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-form button {
  width: 100%;
  padding: 11px 12px;
  background: var(--text);
  color: #FDF6EC;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.login-error {
  font-size: 12px;
  color: #C0392B;
  min-height: 16px;
}

/* ============================================================
   BOOK SELECTION
   ============================================================ */
.book-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: row;
  gap: 14px;
  align-items: flex-start;
  cursor: pointer;
  margin-bottom: 12px;
}

.book-cover {
  width: 48px;
  height: 64px;
  border-radius: 4px;
  flex-shrink: 0;
  overflow: hidden;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-info {
  flex: 1;
}

.book-info h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.book-info p {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
}

.chapter-count {
  font-size: 12px;
  color: var(--accent);
}

/* ============================================================
   CHAPTER LIST
   ============================================================ */
.chapter-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}

.chapter-label {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.chapter-name {
  font-size: 16px;
  flex: 1;
}

.chapter-arrow {
  color: var(--accent);
  flex-shrink: 0;
}

/* ============================================================
   READER
   ============================================================ */
.reader-body {
  padding: 20px;
  font-size: 20px;
  line-height: 2;
}

.reader-body p {
  text-indent: 1.5em;
  margin-bottom: 0.75em;
}

.word {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.word-highlight {
  background: var(--highlight-word);
  border-radius: 2px;
}

.sentence-highlight {
  background: var(--highlight-sentence);
  border-radius: 2px;
}

/* ============================================================
   MODAL OVERLAY
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 100;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   MODAL BASE
   NOTE: modals stay in the DOM at all times for smooth animation.
   .hidden is NOT applied to modals. Instead they slide off-screen
   with translateY(100%) and use pointer-events:none.
   ============================================================ */
.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 300ms ease-out;
  will-change: transform;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  max-width: 768px;
  margin: 0 auto;
}

.modal.visible {
  transform: translateY(0);
  pointer-events: auto;
}

#dict-modal  { height: 70vh; max-height: 70vh; }
#ai-modal    { height: 65vh; max-height: 65vh; }

@media (max-width: 768px) {
  .modal {
    height: calc(100vh - 3px) !important;
    max-height: calc(100vh - 3px) !important;
    top: 3px;
  }
}

/* Modal handle bar */
.modal-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
}

.modal-handle::after {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: #D0C4B0;
  border-radius: 2px;
}

/* Modal close button */
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  font-size: 22px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modal body (scrollable content area) */
.modal-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 24px;
}

/* Dictionary iframe */
#dict-modal-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ============================================================
   AI MODAL CONTENT
   ============================================================ */
.ai-quote {
  background: var(--input-bg);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 0 6px 6px 0;
  margin-bottom: 16px;
  font-size: 14px;
  font-style: italic;
}

.ai-section-label {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.ai-section-content {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.ai-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 0;
  color: var(--accent);
  font-size: 14px;
}

.ai-stream-content {
  padding: 0 16px 16px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: #333;
  line-height: 1.8;
  word-break: keep-all;
}

/* ============================================================
   HISTORY MODAL CONTENT
   ============================================================ */
.history-list {
  list-style: none;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.history-word {
  font-size: 16px;
  font-weight: bold;
}

.history-right {
  text-align: right;
  flex-shrink: 0;
}

.history-meta {
  font-size: 11px;
  color: var(--accent);
  line-height: 1.5;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 0 24px;
  font-size: 13px;
  color: var(--accent);
}

.history-pagination button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.history-pagination button:disabled {
  opacity: 0.3;
  cursor: default;
}
