:root {
  --bg-ink: #1f2329;
  --bg-paper: #f7f1df;
  --bg-paper-dark: #efe6cf;
  --line: #c7bca2;
  --accent: #2e6b4a;
  --ok: #3c7a2a;
  --warn: #a33f2e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--bg-ink);
  font-family: Georgia, "Times New Roman", serif;
  background: linear-gradient(120deg, #d9cfb0 0%, #ebdfc0 35%, #d8caa4 100%);
  min-height: 100vh;
}

body.auth-modal-open {
  overflow: hidden;
}

.paper-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 33px,
    rgba(105, 92, 62, 0.08) 34px
  );
  opacity: 0.65;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1100px, 94vw);
  margin: 24px auto 48px;
  display: grid;
  gap: 16px;
}

.card {
  background: radial-gradient(circle at top left, var(--bg-paper), var(--bg-paper-dark));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(63, 50, 26, 0.14);
  padding: 18px;
}

.workspace-shell {
  display: grid;
  gap: 16px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.workspace-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 26px;
  padding: 4px 12px 0;
  margin-bottom: 20px;
}

.workspace-tab {
  position: relative;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #4f617a;
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.04rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 8px 1px 12px;
  text-align: center;
  transition: color 140ms ease, transform 140ms ease;
}

.workspace-tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  border-radius: 999px;
  background: transparent;
  transform: scaleX(0.28);
  transform-origin: center;
  transition: background 140ms ease, transform 140ms ease;
}

.workspace-tab:hover {
  color: #264362;
  transform: translateY(-1px);
}

.workspace-tab.is-active {
  color: #2f67c8;
}

.workspace-tab.is-active::after {
  background: #4f8fe6;
  transform: scaleX(1);
}

.workspace-tab:focus-visible {
  outline: 3px solid rgba(47, 125, 225, 0.2);
  outline-offset: 4px;
}

.home-panel {
  display: grid;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #1e2d44;
}

.brand-logo {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-copy {
  display: grid;
  gap: 2px;
  align-items: center;
}

.brand-title {
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-subtitle {
  display: block;
  color: #4f617a;
  font-size: 1.01rem;
  line-height: 1.25;
}

.subtitle {
  font-size: 1.15rem;
  margin: 8px 0 0;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.auth-actions-desktop {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.mobile-float-nav {
  display: none;
}

.mobile-float-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1px solid #cfdced;
  background: #f8fbff;
  color: #3f5775;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.mobile-float-action i {
  font-size: 1.05rem;
}

.mobile-float-action:hover {
  background: #edf3fc;
  border-color: #b5c9e4;
  color: #274467;
}

.mobile-float-action--logout {
  border-color: #efcdcd;
  background: #fff4f4;
  color: #b44848;
}

.mobile-float-action--logout:hover {
  background: #fdeaea;
  border-color: #e6b2b2;
  color: #a33a3a;
}

.welcome {
  font-size: 1rem;
  color: #4a4336;
}

.email-status-pill {
  display: inline-block;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid #b88379;
  background: #f9e9e5;
  color: #7f2f24;
}

.grid-two {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  grid-template-areas:
    "flash rings"
    "flash quick";
  gap: 16px;
}

#flashcardsSection {
  grid-area: flash;
}

.rings-card {
  grid-area: rings;
}

.quick-structure-card {
  grid-area: quick;
}

.section h2 {
  margin-top: 0;
  font-size: 1.6rem;
}

.lesson-journey-card {
  padding: 16px;
  border: 1px solid #d2dbe9;
  background: linear-gradient(160deg, #f8fbff 0%, #eef4fb 56%, #f7f1df 100%);
  box-shadow: 0 14px 30px rgba(56, 74, 104, 0.12);
}

.lesson-head {
  display: grid;
  gap: 6px;
}

.lesson-head h2 {
  margin: 0;
  letter-spacing: 0.01em;
}

.lesson-objective {
  margin: 0;
  color: #3f4f69;
}

.lesson-meta,
.lesson-kpi {
  margin-top: 8px;
  color: #51627d;
  font-size: 0.95rem;
}

.lesson-list {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.lesson-tile {
  --lesson-accent: #2f7de1;
  --lesson-accent-soft: #dce9ff;
  width: 100%;
  text-align: left;
  border: 1px solid #d9e2ee;
  border-radius: 16px;
  background: linear-gradient(160deg, #ffffff 0%, #f8fbff 100%);
  padding: 12px;
  display: grid;
  gap: 8px;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background 150ms ease;
  box-shadow: 0 4px 14px rgba(48, 69, 99, 0.08);
}

.lesson-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(48, 69, 99, 0.14);
  border-color: color-mix(in srgb, var(--lesson-accent) 42%, #c5d3e7 58%);
}

.lesson-tile:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--lesson-accent) 56%, #9eb9df 44%);
  outline-offset: 2px;
}

.lesson-tile.is-active {
  border-color: color-mix(in srgb, var(--lesson-accent) 55%, #b7c8de 45%);
  background:
    linear-gradient(160deg, #ffffff 0%, color-mix(in srgb, var(--lesson-accent-soft) 45%, #ffffff 55%) 100%);
  box-shadow: 0 12px 22px rgba(48, 69, 99, 0.18);
}

.lesson-tile.is-complete {
  box-shadow: 0 10px 20px rgba(45, 95, 34, 0.17);
}

.lesson-tile.is-locked,
.lesson-tile:disabled {
  opacity: 0.64;
  cursor: not-allowed;
  box-shadow: none;
}

.lesson-tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lesson-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: #ffffff;
  border: 1px solid #cfdaea;
  color: #46607f;
  box-shadow: none;
}

.lesson-icon i {
  font-size: 0.95rem;
}

.lesson-state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--lesson-accent) 30%, #c9d7ea 70%);
  background: color-mix(in srgb, var(--lesson-accent-soft) 55%, #ffffff 45%);
  color: #2d3d54;
  font-size: 0.78rem;
  font-weight: 700;
}

.lesson-state-pill.is-done {
  background: #e8f6ec;
  border-color: #98c9a5;
  color: #24643a;
}

.lesson-state-pill.is-active {
  background: #e7f0ff;
  border-color: #9db6df;
  color: #254369;
}

.lesson-state-pill.is-locked {
  background: #eceff4;
  border-color: #c8d0de;
  color: #5e6b7d;
}

.lesson-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1f2c40;
  line-height: 1.2;
}

.lesson-subtitle {
  font-size: 0.86rem;
  line-height: 1.3;
  color: #53637c;
  min-height: 2.6em;
}

.lesson-progress-track {
  position: relative;
  height: 7px;
  border-radius: 999px;
  background: #e4ebf5;
  overflow: hidden;
}

.lesson-progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--lesson-accent), color-mix(in srgb, var(--lesson-accent) 45%, #7fc6ff 55%));
}

.lesson-foot {
  font-size: 0.8rem;
  color: #5a6a81;
}

.mode-row,
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.rings-panel {
  margin-top: 12px;
}

.rings-card {
  padding: 14px;
  border: 1px solid #aa9c7d;
  border-radius: 12px;
  background: rgba(255, 251, 240, 0.9);
}

.rings-head h3 {
  margin: 0;
  font-size: 1.15rem;
}

.rings-head p {
  margin: 4px 0 0;
  color: #504734;
}

.rings-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.ring-item {
  text-align: center;
}

.ring-track {
  --ring-progress: 0%;
  --ring-color: #2f7a50;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  margin: 0 auto;
  background:
    conic-gradient(var(--ring-color) var(--ring-progress), #dacfb4 0),
    radial-gradient(circle at 50% 50%, #fffaf0 60%, transparent 61%);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(72, 59, 31, 0.18);
}

.ring-core {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #fffaf0;
  border: 1px solid #b8aa8d;
  display: grid;
  place-items: center;
}

.ring-value {
  font-size: 0.88rem;
  font-weight: 700;
  color: #3f3729;
}

.ring-word { --ring-color: #2f7a50; }
.ring-memory { --ring-color: #a03b2c; }
.ring-consistency { --ring-color: #ba7a19; }

.ring-track.is-closed {
  box-shadow: inset 0 0 0 1px rgba(72, 59, 31, 0.18), 0 0 0 3px rgba(255, 215, 120, 0.45);
}

.ring-label {
  margin-top: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

.ring-meta {
  margin-top: 3px;
  font-size: 0.85rem;
  color: #504734;
}

.rings-perfect {
  margin: 12px 0 0;
  color: #695218;
  font-weight: 700;
}

.btn {
  border: 1px solid #7f755f;
  background: #f8f3e6;
  color: #1f2329;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

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

.btn-soft {
  background: #f2ebd8;
}

.btn-warn {
  background: var(--warn);
  border-color: #7f2f24;
  color: #fff;
}

.btn-good {
  background: var(--ok);
  border-color: #2a531e;
  color: #fff;
}

.mode-btn.active {
  background: #1f2329;
  color: #fff;
  border-color: #111;
}

.flashcard {
  margin-top: 10px;
  padding: 20px;
  min-height: 230px;
  border-radius: 12px;
  border: 2px dashed #9a8e74;
  background: rgba(255, 252, 242, 0.75);
}

.flashcard-label {
  font-size: .95rem;
  color: #4e473a;
}

.flashcard-front,
.flashcard-back-main {
  font-size: clamp(1.7rem, 4.5vw, 2.7rem);
  line-height: 1.25;
  margin-top: 10px;
}

.flashcard-back-meta {
  margin-top: 10px;
  font-size: 1.05rem;
  color: #423d31;
}

.counter,
.muted {
  color: #4e473a;
}

.hidden { display: none; }

.tips-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.tips-list li {
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.drill-box {
  border: 2px dashed #9a8e74;
  border-radius: 12px;
  padding: 18px;
  background: rgba(255, 252, 242, 0.75);
}

.drill-script {
  font-size: clamp(2rem, 6vw, 3.6rem);
  margin-bottom: 10px;
}

.drill-reveal {
  font-size: 1.1rem;
  line-height: 1.5;
}

.footer-note {
  font-size: 1.05rem;
}

.thai-ai-section {
  border-style: solid;
}

.thai-ai-chat {
  margin-top: 12px;
  border: 1px solid #b8ac90;
  border-radius: 12px;
  background: rgba(255, 253, 246, 0.84);
  padding: 12px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thai-ai-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.thai-ai-row.is-user {
  justify-content: flex-end;
}

.thai-ai-row.is-system {
  justify-content: stretch;
  align-items: stretch;
}

.thai-ai-row.is-user .thai-ai-avatar {
  order: 2;
}

.thai-ai-row.is-user .thai-ai-msg {
  order: 1;
}

.thai-ai-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #a79877;
  background: #f0e6cd;
  flex: 0 0 38px;
}

.thai-ai-msg {
  border: 1px solid #c9bda2;
  border-radius: 12px;
  padding: 10px 12px;
  width: fit-content;
  max-width: calc(100% - 56px);
  box-shadow: 0 3px 10px rgba(60, 52, 35, 0.08);
}

.thai-ai-msg.is-user {
  justify-self: end;
  border-color: #9bbfdf;
  background: #e9f4ff;
}

.thai-ai-msg.is-assistant {
  justify-self: start;
  border-color: #cbbd9c;
  background: #fcf8ee;
}

.thai-ai-msg.is-system {
  width: 100%;
  max-width: 100%;
  box-shadow: none;
}

.thai-ai-msg.is-system .thai-ai-msg-head {
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.thai-ai-msg.is-system.is-success {
  color: #2d5f21;
  border-color: #7ca470;
  background: #eaf7e5;
}

.thai-ai-msg.is-system.is-error {
  color: #7f2f24;
  border-color: #b88379;
  background: #f9e9e5;
}

.thai-ai-msg.is-system.is-info {
  color: #244e77;
  border-color: #86a8cb;
  background: #eaf2fb;
}

.thai-ai-msg-head {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
  color: #5d5342;
}

.thai-ai-msg-body {
  white-space: pre-wrap;
  line-height: 1.45;
}

.thai-ai-msg-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.thai-ai-play {
  padding: 7px 10px;
  font-size: 0.95rem;
}

.thai-ai-add {
  padding: 7px 10px;
  font-size: 0.95rem;
}

.thai-ai-btn-label {
  white-space: nowrap;
}

.thai-ai-form {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.thai-ai-form textarea,
.thai-ai-form input[type="text"] {
  width: 100%;
  font-size: 1rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #8d836e;
  background: #fffef8;
  resize: vertical;
}

.thai-ai-form input[type="text"] {
  min-height: 48px;
  font-size: 1.05rem;
  padding: 12px;
}

.auth-page {
  max-width: 680px;
}

.auth-inline-card {
  padding: 12px;
}

.auth-card h1 {
  margin: 0;
}

.auth-tabs {
  margin-top: 16px;
}

.auth-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.auth-form input {
  width: 100%;
  font-size: 1rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #8d836e;
  background: #fffef8;
}

.auth-form select {
  width: 100%;
  font-size: 1rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #8d836e;
  background: #fffef8;
}

.settings-check {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  padding: 10px 2px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.settings-check-copy {
  display: block;
  color: #3c3427;
  line-height: 1.45;
}

.settings-check-title {
  display: block;
  font-weight: 700;
  font-size: 1rem;
}

.settings-switch-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
}

.settings-switch-wrap input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.settings-switch {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  display: block;
  overflow: hidden;
  background: #d5dfec;
  box-shadow: inset 0 0 0 1px rgba(47, 103, 200, 0.08);
  transition: background 180ms ease, box-shadow 180ms ease;
}

.settings-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff 0%, #f3f7fd 100%);
  box-shadow: 0 1px 2px rgba(34, 52, 78, 0.22), 0 3px 8px rgba(34, 52, 78, 0.12);
  transition: transform 180ms ease;
}

.settings-switch-wrap input[type="checkbox"]:checked + .settings-switch {
  background: linear-gradient(180deg, #2f7de1 0%, #2f67c8 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.settings-switch-wrap input[type="checkbox"]:checked + .settings-switch .settings-switch-knob {
  transform: translateX(20px);
}

.settings-switch-wrap input[type="checkbox"]:focus-visible + .settings-switch {
  box-shadow: 0 0 0 4px rgba(47, 125, 225, 0.22);
}

.settings-check:has(input[type="checkbox"]:checked) {
  background: transparent;
}

.alert-error,
.alert-success {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid;
}

.alert-error {
  color: #7f2f24;
  border-color: #b88379;
  background: #f9e9e5;
}

.alert-success {
  color: #2d5f21;
  border-color: #7ca470;
  background: #eaf7e5;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 23, 14, 0.55);
  backdrop-filter: blur(2px);
}

.auth-modal-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 94vw);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 20px;
  animation: authModalIn 180ms ease-out;
}

.settings-modal-panel {
  width: min(560px, 94vw);
}

.admin-modal-panel {
  width: min(860px, 96vw);
}

.auth-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #8d836e;
  background: #f8f1dd;
  color: #1f2329;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.auth-modal-subtitle {
  margin-right: 32px;
}

.auth-modal-form {
  margin-top: 10px;
}

.auth-modal-toggle {
  margin: 10px 0 0;
  color: #4e473a;
}

.admin-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-search-row input {
  flex: 1;
}

.admin-ai-overview {
  margin-top: 12px;
  margin-bottom: 8px;
}

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

.admin-ai-card {
  border: 1px solid #d4deec;
  border-radius: 12px;
  background: #f8fbff;
  padding: 12px;
}

.admin-ai-card-title {
  margin: 0;
  font-size: 0.86rem;
  color: #4f6584;
  font-weight: 700;
}

.admin-ai-card-cost {
  margin-top: 6px;
  font-size: 1.28rem;
  font-weight: 800;
  color: #1f2f46;
  letter-spacing: 0.01em;
}

.admin-ai-card-meta {
  margin-top: 6px;
  font-size: 0.84rem;
  color: #4f6584;
}

.admin-ai-note {
  margin: 8px 2px 0;
  font-size: 0.8rem;
  color: #5d7392;
}

.admin-ai-empty {
  border: 1px dashed #d0dbeb;
  border-radius: 12px;
  padding: 10px 12px;
  color: #5d7392;
  background: #f8fbff;
  font-size: 0.9rem;
}

.admin-user-status {
  margin-top: 10px;
  min-height: 20px;
}

.admin-user-status.is-error {
  color: #a13d3d;
}

.admin-user-results {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.admin-user-empty {
  border: 1px dashed #d0dbeb;
  border-radius: 12px;
  padding: 14px;
  color: #5d7392;
  background: #f8fbff;
}

.admin-user-row {
  border: 1px solid #d4deec;
  border-radius: 12px;
  background: #f8fbff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.admin-user-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.admin-user-name {
  font-weight: 700;
  color: #1f2f46;
}

.admin-user-email {
  margin-top: 2px;
  color: #4f6584;
  font-size: 0.92rem;
}

.admin-user-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  border: 1px solid #ccd8eb;
  background: #eef4ff;
  color: #3c5170;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 5px 8px;
}

.admin-pill.is-confirmed {
  background: #e8f6ee;
  border-color: #b9e0c8;
  color: #276942;
}

.admin-pill.is-pending {
  background: #fff4e8;
  border-color: #f0d2b1;
  color: #94511f;
}

.admin-pill.is-admin {
  background: #e5efff;
  border-color: #c2d6f8;
  color: #24579f;
}

.admin-user-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.auth-link-btn {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* Keep modal and auth forms truly hidden when JS/PHP adds .hidden */
.auth-modal.hidden,
.auth-form.hidden,
.auth-modal-toggle.hidden {
  display: none;
}

@keyframes authModalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modern Flat UI System */
:root {
  --bg-ink: #1b2738;
  --bg-paper: #ffffff;
  --bg-paper-dark: #f7faff;
  --line: #d5dfed;
  --line-strong: #b8c7de;
  --accent: #2f7de1;
  --accent-press: #1f66c2;
  --ok: #2f9b52;
  --warn: #d44e4e;
  --canvas: #edf3fb;
}

body {
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--bg-ink);
  background: linear-gradient(165deg, #edf3fb 0%, #f5f8fd 48%, #eef4fc 100%);
}

.paper-bg {
  background:
    radial-gradient(circle at 8% 6%, rgba(82, 146, 238, 0.12) 0%, transparent 28%),
    radial-gradient(circle at 92% 10%, rgba(62, 184, 157, 0.12) 0%, transparent 30%),
    radial-gradient(circle at 65% 88%, rgba(91, 111, 244, 0.10) 0%, transparent 32%);
  opacity: 1;
}

.app {
  width: min(1140px, 94vw);
  margin: 20px auto 42px;
  gap: 14px;
}

.card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: none;
}

.hero.card {
  background: linear-gradient(160deg, #ffffff 0%, #f5f9ff 100%);
}

.hero h1 {
  font-size: clamp(1.65rem, 3.7vw, 2.35rem);
  letter-spacing: -0.01em;
}

.subtitle {
  color: #4f617a;
  font-size: 1.03rem;
}

.brand-lockup {
  gap: 14px;
}

.brand-logo {
  width: 72px;
  height: 72px;
}

.brand-title {
  font-size: clamp(1.25rem, 2.2vw, 1.7rem);
}

.brand-subtitle {
  font-size: 1rem;
}

.welcome {
  color: #354c68;
  font-weight: 600;
}

.email-status-pill {
  border-color: #f0bc8f;
  background: #fff1e4;
  color: #9b4f0e;
}

.section h2 {
  color: #1e2d44;
  font-size: 1.45rem;
}

.lesson-journey-card {
  background: var(--bg-paper);
  border-color: var(--line);
  box-shadow: none;
}

.lesson-meta,
.lesson-kpi,
.muted,
.counter {
  color: #58708f;
}

.lesson-list {
  gap: 12px;
}

.lesson-tile {
  border-color: var(--line);
  background: linear-gradient(160deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: none;
  transition: border-color 150ms ease, background 150ms ease;
}

.lesson-tile:hover {
  transform: none;
  box-shadow: none;
  border-color: color-mix(in srgb, var(--lesson-accent) 48%, #bfd2eb 52%);
}

.lesson-tile.is-active {
  box-shadow: none;
}

.lesson-tile.is-complete {
  box-shadow: none;
  border-color: #9dcbab;
}

.mode-row,
.actions-row {
  gap: 10px;
}

.btn {
  border: 1px solid var(--line-strong);
  background: #f8fbff;
  color: #1d2a3d;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.97rem;
  font-weight: 600;
  box-shadow: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn:hover {
  filter: none;
  background: #f0f5fc;
}

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

.btn-primary:hover {
  background: var(--accent-press);
  border-color: var(--accent-press);
}

.btn-soft {
  background: #f4f8ff;
  border-color: #ccdbef;
}

.btn-warn {
  background: #e25656;
  border-color: #e25656;
  color: #ffffff;
}

.btn-warn:hover {
  background: #c94a4a;
  border-color: #c94a4a;
  color: #ffffff;
}

.btn-good {
  background: #2f9b52;
  border-color: #2f9b52;
  color: #ffffff;
}

.mode-btn.active {
  background: #1f2f47;
  border-color: #1f2f47;
}

.flashcard,
.drill-box {
  border: 1px solid #dbe5f2;
  border-radius: 14px;
  background: #f8fbff;
}

.flashcard {
  min-height: 220px;
}

.flashcard-label {
  color: #59718f;
}

.flashcard-front,
.flashcard-back-main {
  color: #1f2e44;
  letter-spacing: -0.01em;
}

.flashcard-back-meta {
  color: #4d6078;
  font-size: 1rem;
}

.rings-card {
  background: #f9fbff;
  border-color: #d5dfed;
}

.rings-head p,
.ring-meta {
  color: #536882;
}

.ring-core {
  background: #ffffff;
  border-color: #c9d8ea;
}

.ring-value {
  color: #2b3f5c;
}

.thai-ai-section {
  background: #ffffff;
  border-color: #d5dfed;
}

.thai-ai-chat {
  border-color: #d9e3f0;
  background: #f8fbff;
}

.thai-ai-avatar {
  border-color: #ccd9ec;
  background: #edf3fc;
}

.thai-ai-msg {
  border-color: #d4dfed;
  background: #ffffff;
  box-shadow: none;
}

.thai-ai-msg.is-user {
  border-color: #bfd3ef;
  background: #eff5ff;
}

.thai-ai-msg.is-assistant {
  border-color: #d6e1f0;
  background: #ffffff;
}

.thai-ai-msg.is-system.is-success {
  border-color: #84b47d;
  background: #edf8e9;
  color: #2f6627;
}

.thai-ai-msg.is-system.is-error {
  border-color: #cb9184;
  background: #faece9;
  color: #844136;
}

.thai-ai-msg.is-system.is-info {
  border-color: #9ec1e5;
  background: #edf4fd;
  color: #275582;
}

.thai-ai-msg-head {
  color: #5b6f89;
}

.thai-ai-form textarea,
.thai-ai-form input[type="text"],
.auth-form input,
.auth-form select {
  border-color: #c7d5e8;
  border-radius: 12px;
  background: #f9fbff;
  color: #22344e;
}

.settings-check {
  background: transparent;
}

.settings-check-copy {
  color: #22344e;
}

.thai-ai-form input[type="text"] {
  min-height: 50px;
}

.auth-inline-card {
  background: #ffffff;
}

.alert-error,
.alert-success {
  border-radius: 12px;
}

.auth-modal-backdrop {
  background: rgba(23, 36, 56, 0.46);
}

.auth-modal-panel {
  background: #ffffff;
  border-color: #d7e1ee;
}

.auth-modal-close {
  border-color: #ccd8ea;
  background: #f3f8ff;
}

.footer-note {
  background: #ffffff;
}

.footer-note a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.footer-note a:hover {
  text-decoration: underline;
}

@media (max-width: 720px) {
  .brand-logo {
    width: 58px;
    height: 58px;
  }

  .brand-copy {
    gap: 1px;
  }

  .brand-subtitle {
    font-size: 0.92rem;
  }

  .workspace-shell {
    gap: 14px;
  }

  .workspace-tabs {
    justify-content: flex-start;
    gap: 18px;
    padding: 0 4px;
    margin-bottom: 14px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .workspace-tabs::-webkit-scrollbar {
    display: none;
  }

  .workspace-tab {
    flex: 0 0 auto;
    font-size: 0.96rem;
    padding-bottom: 10px;
  }

  .grid-two {
    grid-template-columns: 1fr;
    grid-template-areas:
      "flash"
      "rings"
      "quick";
  }
  .app { width: 95vw; }
  .brand-logo { width: 32px; height: 32px; }
  .brand-title { font-size: 1.05rem; }
  .btn { width: 100%; }
  .is-authenticated .app {
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .auth-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
  }
  .auth-actions .btn {
    width: auto;
    white-space: nowrap;
  }
  .auth-actions-desktop {
    display: none;
  }
  .mobile-float-nav {
    position: fixed;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 24;
    display: inline-flex;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid #d7e2f0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 12px 28px rgba(33, 56, 88, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .mobile-float-action {
    width: 46px;
    height: 46px;
    border-radius: 12px;
  }
  .admin-search-row {
    flex-wrap: wrap;
  }
  .admin-ai-grid {
    grid-template-columns: 1fr;
  }
  .admin-search-row .btn,
  .admin-user-actions .btn {
    width: auto;
  }
  .thai-ai-msg-actions {
    flex-wrap: nowrap;
  }
  .thai-ai-msg-actions .btn {
    width: auto;
  }
  .rings-grid { grid-template-columns: 1fr; }
  .ring-track { width: 96px; height: 96px; }
  .lesson-list { grid-template-columns: 1fr; }
  .lesson-tile { width: 100%; }
  .auth-modal {
    align-items: end;
    padding: 8px;
  }
  .auth-modal-panel {
    width: 100%;
    max-height: min(92vh, 720px);
  }

  .thai-ai-play .thai-ai-btn-label,
  .thai-ai-add .thai-ai-btn-label {
    display: none;
  }

  .thai-ai-play,
  .thai-ai-add {
    min-width: 40px;
    padding: 7px 9px;
  }
}

@media (min-width: 1024px) {
  .thai-ai-msg {
    max-width: min(72%, 840px);
  }
}
