:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #65736f;
  --line: #d8dfdc;
  --paper: #fbfaf5;
  --panel: #ffffff;
  --sage: #246b5c;
  --sage-dark: #17483e;
  --gold: #f0b84f;
  --coral: #d96c5f;
  --blue: #3c6ea8;
  --shadow: 0 18px 50px rgba(23, 33, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fffefb;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 16px;
  color: var(--ink);
  background: #fffefb;
  outline: none;
}

input:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px rgba(36, 107, 92, 0.12);
}

.auth-screen,
.home-screen {
  min-height: 100vh;
  padding: 32px;
}

.auth-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 28px;
  align-items: stretch;
}

.auth-visual {
  min-height: 560px;
  border-radius: 8px;
  padding: 44px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: #fffdf6;
  background:
    linear-gradient(135deg, rgba(16, 42, 38, 0.9), rgba(60, 110, 168, 0.72)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='960' height='680' viewBox='0 0 960 680'%3E%3Crect width='960' height='680' fill='%23fbfaf5'/%3E%3Cg fill='none' stroke='%23246b5c' stroke-width='5' opacity='0.25'%3E%3Cpath d='M88 118h420M88 184h520M88 250h340M88 316h462M88 382h390M88 448h500'/%3E%3C/g%3E%3Cg fill='%23f0b84f' opacity='0.72'%3E%3Crect x='642' y='136' width='58' height='340' rx='8'/%3E%3Crect x='718' y='196' width='58' height='280' rx='8'/%3E%3C/g%3E%3Cpath d='M618 530c74-52 150-56 228-10' stroke='%23d96c5f' stroke-width='14' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
}

.auth-visual h1,
.home-header h1 {
  margin: 0;
  line-height: 1.1;
}

.auth-visual h1 {
  max-width: 720px;
  font-size: 46px;
}

.auth-visual p:last-child {
  max-width: 680px;
  margin: 18px 0 0;
  color: rgba(255, 253, 246, 0.82);
  font-size: 18px;
  line-height: 1.7;
}

.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  align-self: center;
  background: #fff;
  box-shadow: 0 12px 34px rgba(23, 33, 31, 0.08);
}

.auth-panel h2 {
  margin: 0;
  font-size: 24px;
}

.auth-hint {
  margin: 8px 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 22px;
}

.auth-tab {
  min-height: 42px;
  border: 0;
  background: #f3f5f1;
  color: var(--muted);
}

.auth-tab.active {
  background: var(--sage);
  color: #fff;
  font-weight: 700;
}

.auth-panel label {
  display: block;
  margin: 14px 0 8px;
  font-weight: 700;
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.password-field input {
  border: 0;
  min-width: 0;
}

.password-field input:focus {
  outline: 0;
}

.password-toggle {
  min-width: 54px;
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  background: #f8f6ef;
  color: var(--muted);
  font-size: 13px;
}

.auth-message {
  min-height: 22px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-message.error {
  color: var(--coral);
}

.auth-message.success {
  color: var(--sage);
}

.full-btn {
  width: 100%;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 12px 0 0;
  text-align: left;
}

.auth-actions {
  display: grid;
  gap: 10px;
}

.model-select-grid,
.model-row-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.model-list {
  display: grid;
  gap: 12px;
}

.model-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfaf6;
}

.model-row label {
  margin: 0;
}

.model-row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.model-enabled {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.model-test-status {
  color: var(--muted);
  font-size: 13px;
}

.home-screen,
.admin-screen {
  display: grid;
  align-content: start;
  gap: 24px;
}

.admin-screen {
  min-height: 100vh;
  padding: 32px;
}

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.home-header h1 {
  font-size: 34px;
}

.account-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.language-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.language-card {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  align-content: end;
  gap: 10px;
  text-align: left;
  color: #fffdf6;
  background:
    linear-gradient(135deg, rgba(23, 72, 62, 0.94), rgba(36, 107, 92, 0.78)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='560' height='300' viewBox='0 0 560 300'%3E%3Crect width='560' height='300' fill='%23fff6df'/%3E%3Cg fill='none' stroke='%23246b5c' stroke-width='4' opacity='0.28'%3E%3Cpath d='M42 58h250M42 110h340M42 162h280'/%3E%3C/g%3E%3Cpath d='M360 222c38-26 78-28 120-4' stroke='%23f0b84f' stroke-width='10' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover;
  box-shadow: 0 12px 34px rgba(23, 33, 31, 0.1);
}

.language-card.french {
  background:
    linear-gradient(135deg, rgba(42, 65, 112, 0.94), rgba(217, 108, 95, 0.72)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='560' height='300' viewBox='0 0 560 300'%3E%3Crect width='560' height='300' fill='%23fff6df'/%3E%3Cg fill='none' stroke='%233c6ea8' stroke-width='4' opacity='0.28'%3E%3Cpath d='M42 58h250M42 110h340M42 162h280'/%3E%3C/g%3E%3Cpath d='M360 222c38-26 78-28 120-4' stroke='%23d96c5f' stroke-width='10' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover;
}

.language-card:hover {
  transform: translateY(-2px);
}

.language-card span {
  color: var(--gold);
  font-weight: 800;
  text-transform: uppercase;
}

.language-card strong {
  font-size: 28px;
}

.language-card small {
  max-width: 360px;
  color: rgba(255, 253, 246, 0.84);
  font-size: 15px;
  line-height: 1.6;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 18px;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(23, 33, 31, 0.06);
}

.admin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.admin-card h2 {
  margin: 0;
  font-size: 22px;
}

.config-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  background: #fbfcfa;
  font-size: 13px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-user-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: #fffefb;
}

.admin-user-row strong,
.admin-user-row span {
  display: block;
}

.admin-user-row span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.admin-user-stats {
  min-width: 92px;
  text-align: right;
}

.ai-config-form {
  display: grid;
  gap: 10px;
}

.ai-config-form label {
  margin-top: 8px;
  font-weight: 700;
}

.key-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0;
}

.key-status-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.key-status-grid span,
.key-status-grid strong {
  display: block;
}

.key-status-grid span {
  color: var(--muted);
  font-size: 13px;
}

.key-status-grid strong {
  margin-top: 5px;
  color: var(--coral);
}

.key-status-grid strong.ok {
  color: var(--sage);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.app-shell.hidden,
.auth-screen.hidden,
.home-screen.hidden,
.admin-screen.hidden {
  display: none;
}

.sidebar {
  background: #102a26;
  color: #f7f4e9;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #fff6df;
  display: grid;
  place-items: center;
}

.brand-mark svg {
  width: 44px;
  height: 44px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand h1,
.hero-band h2,
.history-head h3,
.review-empty h3,
.review-report h3 {
  margin: 0;
}

.brand h1 {
  font-size: 24px;
  line-height: 1.15;
}

.tabs {
  display: grid;
  gap: 8px;
}

.user-strip {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.user-strip span {
  overflow-wrap: anywhere;
  color: rgba(247, 244, 233, 0.82);
  font-size: 13px;
}

.user-strip button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: #f7f4e9;
  color: #102a26;
}

.tab {
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #f7f4e9;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  text-align: left;
}

.tab span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}

.tab.active {
  background: #f7f4e9;
  color: #102a26;
}

.stats-grid {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.stat {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.06);
}

.stat span {
  color: rgba(247, 244, 233, 0.75);
}

.stat strong {
  font-size: 20px;
}

.main-content {
  min-width: 0;
  padding: 32px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.hero-band {
  min-height: 220px;
  border-radius: 8px;
  padding: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 24px;
  align-items: end;
  background:
    linear-gradient(120deg, rgba(16, 42, 38, 0.92), rgba(36, 107, 92, 0.82)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='360' viewBox='0 0 900 360'%3E%3Crect width='900' height='360' fill='%23f7f4e9'/%3E%3Cg fill='none' stroke='%23246b5c' stroke-width='4' opacity='0.32'%3E%3Cpath d='M65 74h285M65 126h360M65 178h240M565 76h180M565 128h260M565 180h210'/%3E%3C/g%3E%3Cg fill='%23f0b84f' opacity='0.72'%3E%3Crect x='478' y='58' width='38' height='230' rx='6'/%3E%3Crect x='524' y='91' width='38' height='197' rx='6'/%3E%3C/g%3E%3Cpath d='M690 256c44-26 83-27 116-3' stroke='%23d96c5f' stroke-width='9' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
  color: #fffdf6;
  box-shadow: var(--shadow);
}

.hero-band h2 {
  max-width: 760px;
  font-size: 34px;
  line-height: 1.16;
}

.topic-prompt {
  max-width: 760px;
  margin: 14px 0 0;
  color: rgba(255, 253, 246, 0.82);
  line-height: 1.65;
}

.topic-card {
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 8px;
  background: rgba(255, 253, 246, 0.12);
  backdrop-filter: blur(8px);
}

.topic-card span,
.topic-card small {
  color: rgba(255, 253, 246, 0.78);
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(23, 33, 31, 0.06);
}

.active-panel {
  display: block;
}

.toolbar,
.writer-footer,
.history-head,
.score-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.level-btn {
  min-height: 40px;
  border: 0;
  background: #f3f5f1;
  color: var(--muted);
  padding: 0 14px;
}

.level-btn.active {
  background: var(--sage);
  color: #fff;
}

.ghost-btn,
.primary-btn {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.primary-btn {
  min-width: 130px;
  border-color: var(--sage);
  background: var(--sage);
  color: #fff;
  font-weight: 700;
}

.ghost-btn:hover,
.primary-btn:hover {
  transform: translateY(-1px);
}

.danger {
  color: var(--coral);
}

.writer-label {
  display: block;
  margin: 22px 0 10px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 310px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: #fffefb;
  outline: none;
}

textarea:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px rgba(36, 107, 92, 0.12);
}

.writer-footer {
  margin-top: 14px;
}

.counter {
  min-width: 110px;
  color: var(--muted);
}

.counter span:first-child {
  color: var(--ink);
  font-weight: 800;
  font-size: 24px;
}

.review-empty {
  min-height: 260px;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.review-empty h3 {
  color: var(--ink);
  font-size: 24px;
}

.hidden {
  display: none;
}

.score-block {
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.score-ring {
  width: 116px;
  height: 116px;
  flex: 0 0 116px;
  border-radius: 50%;
  background: conic-gradient(var(--sage) var(--score-deg, 0deg), #e8eee9 0deg);
  display: grid;
  place-items: center;
  position: relative;
}

.score-ring::before {
  content: "";
  position: absolute;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #fff;
}

.score-ring span,
.score-ring small {
  position: relative;
  z-index: 1;
}

.score-ring span {
  font-size: 34px;
  font-weight: 900;
}

.score-ring small {
  margin-top: 46px;
  margin-left: -24px;
  color: var(--muted);
}

.rubric {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.rubric-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.rubric-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.rubric-item strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

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

.feedback-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fffefb;
}

.feedback-grid h4 {
  margin: 0 0 12px;
}

#issueList {
  margin: 0;
  padding-left: 20px;
  line-height: 1.65;
}

#strengthList,
#grammarList,
#vocabList,
#practiceList {
  margin: 0;
  padding-left: 20px;
  line-height: 1.65;
}

.rewrite-box {
  color: var(--muted);
  line-height: 1.7;
  white-space: pre-wrap;
}

.feedback-grid article:nth-child(5),
.feedback-grid article:nth-child(7) {
  grid-column: span 2;
}

.history-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 10px;
  background: #fffefb;
}

.history-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.history-item strong {
  font-size: 18px;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.empty-history {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 920px) {
  .auth-screen {
    grid-template-columns: 1fr;
  }

  .auth-visual {
    min-height: 380px;
  }

  .language-choice {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hero-band,
  .feedback-grid {
    grid-template-columns: 1fr;
  }

  .feedback-grid article:nth-child(5),
  .feedback-grid article:nth-child(7) {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .auth-screen,
  .home-screen,
  .admin-screen {
    padding: 16px;
  }

  .auth-screen {
    min-height: 100svh;
    gap: 14px;
  }

  .auth-visual {
    min-height: 230px;
    padding: 22px;
  }

  .auth-visual h1 {
    font-size: 28px;
  }

  .auth-visual p:last-child {
    font-size: 15px;
    line-height: 1.55;
  }

  .auth-panel {
    align-self: start;
    padding: 18px;
  }

  .home-header,
  .account-box {
    align-items: stretch;
    flex-direction: column;
  }

  .home-header h1 {
    font-size: 28px;
  }

  .language-card {
    min-height: 220px;
  }

  .admin-user-row,
  .admin-card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-user-stats {
    text-align: left;
  }

  .key-status-grid {
    grid-template-columns: 1fr;
  }

  .main-content {
    padding: 16px;
  }

  .hero-band {
    padding: 22px;
  }

  .hero-band h2 {
    font-size: 24px;
  }

  textarea {
    min-height: 42svh;
    padding: 16px;
  }

  .toolbar,
  .writer-footer,
  .history-head,
  .score-block {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented,
  .rubric,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .primary-btn,
  .ghost-btn {
    width: 100%;
  }

  .score-ring {
    margin: 0 auto;
  }
}
