:root {
  --bg: #efe9dd;
  --bg-accent: #dccdb0;
  --paper: #fcf8f1;
  --paper-strong: #fffdf8;
  --ink: #1b2729;
  --muted: #5a6668;
  --line: #d7ccb8;
  --teal: #1f7a72;
  --teal-strong: #155c56;
  --orange: #b96a32;
  --shadow: 0 14px 32px rgba(27, 39, 41, 0.1);
  --radius-lg: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Source Sans 3", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 8%, rgba(31, 122, 114, 0.14), transparent 30%),
    radial-gradient(circle at 92% 15%, rgba(185, 106, 50, 0.12), transparent 32%),
    linear-gradient(170deg, var(--bg), var(--bg-accent));
  padding: 1.2rem;
}

.page-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(30, 36, 35, 0.035) 0.45px, transparent 0.45px);
  background-size: 6px 6px;
  opacity: 0.45;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto 1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--teal), var(--teal-strong));
  color: #fff;
  font-weight: 700;
}

.brand-title {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.25rem;
}

.brand-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.85);
}

.main-wrap {
  max-width: 1180px;
  margin: 0 auto;
}

.card {
  background: linear-gradient(180deg, var(--paper), var(--paper-strong));
  border: 1px solid rgba(215, 204, 184, 0.88);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 540px;
  margin: 2.4rem auto;
  padding: 1.8rem;
  animation: rise 460ms ease;
}

h1,
h2,
h3 {
  font-family: "Fraunces", serif;
  margin-top: 0;
}

h1 {
  margin-bottom: 0.35rem;
}

.muted {
  color: var(--muted);
}

.auth-tabs {
  display: inline-flex;
  gap: 0.45rem;
  margin-top: 0.8rem;
  margin-bottom: 0.8rem;
  background: #f1eadf;
  border-radius: 999px;
  padding: 0.26rem;
}

.tab {
  border: 0;
  border-radius: 999px;
  padding: 0.48rem 0.9rem;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 3px 10px rgba(31, 122, 114, 0.12);
}

.auth-form {
  display: grid;
  gap: 0.8rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.95rem;
}

input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.68rem 0.75rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

input:focus-visible,
button:focus-visible,
.history-item:focus-visible,
.word-token:focus-visible {
  outline: 3px solid rgba(31, 122, 114, 0.28);
  outline-offset: 2px;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button {
  font: inherit;
  cursor: pointer;
}

.primary-button {
  border: 0;
  border-radius: 10px;
  padding: 0.68rem 1rem;
  background: linear-gradient(135deg, var(--teal), var(--teal-strong));
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  filter: brightness(1.04);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.76rem;
  background: #fff;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--orange);
  padding: 0;
  font-weight: 600;
}

.icon-button {
  border: 0;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  background: #efe7d6;
  color: var(--ink);
  position: absolute;
  right: 0.8rem;
  top: 0.8rem;
}

.form-message {
  min-height: 1.15rem;
  margin: 0.25rem 0 0.7rem;
  color: var(--teal-strong);
}

.form-message.error {
  color: #a23a2a;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: 1rem;
  animation: rise 450ms ease;
}

.reader-card {
  padding: 1.15rem;
}

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

.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.reader-header h2 {
  margin: 0.2rem 0 0;
  font-size: 1.4rem;
}

.topic-row {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 0.95rem;
}

.topic-row input {
  flex: 1;
}

.passage {
  min-height: 360px;
  max-height: min(65vh, 760px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 1rem;
  line-height: 1.85;
  background: #fff;
  font-size: 1.08rem;
}

.passage.empty {
  color: var(--muted);
}

.word-token {
  border-radius: 5px;
  padding: 0.04rem 0.1rem;
  transition: background 140ms ease, color 140ms ease;
  cursor: pointer;
}

.word-token:hover {
  background: rgba(31, 122, 114, 0.15);
}

.sidebar {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.stats-card,
.favorites-card,
.history-card {
  padding: 1rem;
}

.stats-card h3,
.favorites-card h3,
.history-card h3 {
  margin-bottom: 0.7rem;
}

.stats-grid {
  display: grid;
  gap: 0.5rem;
}

.stat-block {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 0.45rem;
}

.stat-label {
  margin: 0;
  color: var(--muted);
}

.stat-value {
  margin: 0;
  font-size: 1.42rem;
  font-family: "Fraunces", serif;
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.favorite-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  background: #fff;
}

.favorite-word {
  font-weight: 600;
}

.history-item {
  border: 1px solid var(--line);
  width: 100%;
  text-align: left;
  background: #fff;
  border-radius: 10px;
  padding: 0.56rem 0.62rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
}

.history-topic {
  font-weight: 600;
}

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

.tooltip {
  position: absolute;
  z-index: 30;
  width: 260px;
  border-radius: 12px;
  border: 1px solid rgba(26, 39, 38, 0.15);
  background: rgba(253, 249, 242, 0.98);
  box-shadow: 0 12px 24px rgba(27, 39, 41, 0.16);
  padding: 0.6rem 0.75rem;
  backdrop-filter: blur(6px);
}

.tooltip-word {
  font-weight: 700;
}

.tooltip-def {
  margin-top: 0.25rem;
}

.tooltip-phonetic {
  margin-top: 0.22rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(22, 27, 28, 0.35);
  display: grid;
  place-items: center;
  z-index: 35;
  padding: 1rem;
}

.modal-card {
  position: relative;
  width: min(700px, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fffefb;
  padding: 1.1rem;
  box-shadow: 0 20px 44px rgba(27, 39, 41, 0.2);
}

.modal-card h3 {
  margin-bottom: 0.8rem;
}

.detail-grid {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 0.95rem;
}

.detail-value {
  margin: 0.12rem 0 0;
}

.toast {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  background: #1f2f30;
  color: #fff;
  border-radius: 10px;
  padding: 0.62rem 0.85rem;
  z-index: 50;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  body {
    padding: 0.9rem;
  }

  .app-grid {
    grid-template-columns: 1fr;
  }

  .passage {
    min-height: 300px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-user {
    width: 100%;
    justify-content: space-between;
  }

  .auth-card {
    padding: 1.2rem;
    margin-top: 1rem;
  }

  .topic-row {
    flex-direction: column;
  }

  .reader-card,
  .stats-card,
  .favorites-card,
  .history-card {
    padding: 0.82rem;
  }
}
