:root {
  color-scheme: light;
  --ink: #1d252f;
  --muted: #687384;
  --line: #d9dee7;
  --paper: #f6f7f9;
  --panel: #ffffff;
  --accent: #d84d32;
  --accent-dark: #af321f;
  --green: #227c5a;
  --blue: #2b6cb0;
  --shadow: 0 18px 50px rgba(21, 30, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f7f5ef 0%, #eef4f8 55%, #f8f8fa 100%);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.app {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 48px);
  margin: 14px auto 24px;
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 18px;
}

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

.app.study-mode .workspace {
  display: none;
}

.app.study-mode .result-panel {
  min-height: calc(100vh - 104px);
}

.workspace,
.result-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 222, 231, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-height: 620px;
}

.topbar,
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.main-tabs {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(217, 222, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.tab-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.tab-button.active {
  border-color: rgba(216, 77, 50, 0.34);
  background: rgba(216, 77, 50, 0.1);
  color: var(--accent-dark);
}

.auth-bar {
  width: min(1180px, calc(100% - 32px));
  min-height: 42px;
  margin: 10px auto 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.auth-bar input {
  width: min(240px, 100%);
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}

.auth-bar input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.14);
}

.auth-bar button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 800;
  cursor: pointer;
}

.auth-status {
  color: var(--green);
  font-weight: 800;
}

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.input-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 24px;
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  flex: 1;
  min-height: 420px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
  color: var(--ink);
  line-height: 1.55;
  outline: none;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.14);
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 8px;
}

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

button#translateButton {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  min-width: 132px;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

button#translateButton:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.result-panel {
  min-height: 620px;
  display: flex;
  flex-direction: column;
}

.result-head span {
  min-width: 34px;
  min-height: 28px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: #edf3f8;
  color: var(--blue);
  font-weight: 800;
}

.results {
  overflow: auto;
  padding: 12px;
}

.results.empty {
  display: grid;
  place-items: center;
  flex: 1;
  color: var(--muted);
  text-align: center;
}

.sentence {
  padding: 16px 14px;
  border-bottom: 1px solid var(--line);
}

.sentence-tools {
  display: flex;
  justify-content: flex-end;
  min-height: 28px;
  margin-bottom: 6px;
}

.tense-help,
.tense-empty {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.tense-help {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(43, 108, 176, 0.24);
  background: #edf3f8;
  color: var(--blue);
  cursor: pointer;
}

.tense-help:hover,
.tense-help:focus,
.tense-help.open {
  border-color: var(--blue);
  background: #dfeefb;
  outline: none;
}

.tense-empty {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  background: #f3f5f7;
  color: var(--muted);
}

.sentence:last-child {
  border-bottom: 0;
}

.original,
.translation {
  margin: 0;
  line-height: 1.7;
}

.original {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.translation {
  margin-top: 7px;
  color: var(--green);
  font-size: 16px;
}

.word {
  border-radius: 5px;
  padding: 1px 2px;
  cursor: help;
}

.word:hover,
.word:focus {
  background: rgba(216, 77, 50, 0.13);
  outline: none;
}

.word.tense-highlight {
  background: rgba(43, 108, 176, 0.16);
  box-shadow: inset 0 -2px 0 rgba(43, 108, 176, 0.42);
}

.tooltip {
  position: fixed;
  z-index: 20;
  max-width: min(390px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid #cfd6e0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(20, 31, 44, 0.18);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  pointer-events: auto;
}

.tooltip strong {
  display: block;
  margin-bottom: 3px;
}

.tooltip small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.tense-tooltip-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.tense-tooltip-row {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  padding: 8px 9px;
  text-align: left;
  cursor: pointer;
}

.tense-tooltip-row:hover,
.tense-tooltip-row:focus {
  border-color: var(--blue);
  outline: none;
}

.tense-tooltip-row span {
  color: var(--blue);
  font-weight: 800;
}

.tense-tooltip-row small {
  margin: 0;
  color: var(--muted);
}

.sentence-tense-details {
  display: grid;
  gap: 6px;
  margin: 0 0 10px auto;
  width: min(390px, 100%);
}

.tense-inline-row {
  display: grid;
  grid-template-columns: minmax(135px, 0.7fr) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
}

.tense-inline-row:hover,
.tense-inline-row:focus {
  border-color: var(--blue);
  outline: none;
}

.tense-inline-row span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.tense-inline-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tense-list {
  display: grid;
  gap: 14px;
  padding: 6px;
}

.study-mode .tense-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.tense-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.tense-group h3 {
  margin: 0;
  padding: 8px 11px;
  background: #edf8d7;
  font-size: 14px;
  letter-spacing: 0;
}

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

.tense-card {
  min-height: 68px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  padding: 9px 11px;
  cursor: pointer;
}

.tense-card:nth-child(2n) {
  border-right: 0;
}

.tense-card:hover,
.tense-card:focus {
  background: #f7fbef;
  outline: none;
}

.tense-card strong,
.tense-card span {
  display: block;
}

.tense-card strong {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 14px;
}

.tense-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.tense-detail {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px 12px 18px;
}

.back-button,
.secondary-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
}

.tense-detail h3 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.tense-short {
  margin: 0 0 14px;
  color: var(--green);
  font-weight: 700;
}

.theory-block {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.theory-block p {
  margin: 0;
  line-height: 1.5;
}

.section-label {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.conjugation-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: #fff;
}

.conjugation-table th,
.conjugation-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
}

.conjugation-table th {
  background: #edf3f8;
  color: var(--blue);
  font-size: 13px;
}

.conjugation-table tr:last-child td {
  border-bottom: 0;
}

.exercise-box {
  margin-top: 16px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.exercise-box .section-label {
  margin-top: 0;
}

.exercise-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.exercise-mode {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fb;
}

.exercise-mode button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.exercise-mode button.active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(20, 31, 44, 0.12);
}

.exercise-prompt {
  margin: 0 0 11px;
  font-weight: 800;
}

.exercise-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

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

.choice-option {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  font-weight: 800;
  cursor: pointer;
}

.choice-option:hover,
.choice-option:focus {
  border-color: var(--blue);
  outline: none;
}

.choice-option.ok {
  border-color: rgba(34, 124, 90, 0.45);
  background: rgba(34, 124, 90, 0.1);
  color: var(--green);
}

.choice-option.bad {
  border-color: rgba(216, 77, 50, 0.45);
  background: rgba(216, 77, 50, 0.1);
  color: var(--accent-dark);
}

.exercise-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.exercise-row input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}

.exercise-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.14);
}

.exercise-row button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  min-height: 38px;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
}

.exercise-row .secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.exercise-feedback {
  min-height: 22px;
  margin: 10px 0 0;
  font-weight: 800;
}

.exercise-feedback.ok {
  color: var(--green);
}

.exercise-feedback.bad {
  color: var(--accent-dark);
}

.library-view {
  display: grid;
  gap: 16px;
  padding: 8px;
}

.upload-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.upload-zone h3 {
  margin: 0 0 6px;
  font-size: 24px;
}

.upload-zone p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.upload-button {
  display: inline-grid;
  place-items: center;
  min-width: 150px;
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.upload-button input {
  display: none;
}

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

.book-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: stretch;
}

.book-open,
.book-delete {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.book-open {
  display: grid;
  gap: 4px;
  min-height: 70px;
  padding: 12px 14px;
  text-align: left;
}

.book-open strong {
  color: var(--ink);
  font-size: 16px;
}

.book-open span,
.library-empty {
  color: var(--muted);
}

.book-delete {
  color: var(--muted);
  font-size: 24px;
}

.reader-view {
  display: grid;
  gap: 14px;
  padding: 8px;
}

.reader-toolbar {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.reader-pager {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.reader-pager input {
  width: 76px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

#translatePageButton {
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

#translatePageButton:disabled {
  opacity: 0.72;
  cursor: wait;
}

.reader-status {
  min-width: 150px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.reader-page {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.book-original {
  font-size: 18px;
  line-height: 1.85;
}

.book-translation {
  margin-top: 18px;
  font-size: 17px;
  line-height: 1.75;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .study-mode .tense-list {
    grid-template-columns: 1fr;
  }

  .workspace,
  .result-panel {
    min-height: auto;
  }

  textarea {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .app {
    width: calc(100% - 18px);
    margin: 9px auto;
    gap: 10px;
  }

  .main-tabs {
    width: calc(100% - 18px);
    margin-top: 9px;
  }

  .auth-bar {
    width: calc(100% - 18px);
    align-items: stretch;
    flex-direction: column;
  }

  .auth-bar input,
  .auth-bar button {
    width: 100%;
  }

  .topbar,
  .result-head,
  .input-shell,
  .main-tabs {
    padding-left: 14px;
    padding-right: 14px;
  }

  h1 {
    font-size: 21px;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  button#translateButton {
    width: 100%;
  }

  .tense-grid,
  .exercise-row,
  .choice-grid,
  .reader-toolbar,
  .upload-zone {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    display: grid;
  }

  .reader-status {
    min-width: 0;
    text-align: left;
  }

  .exercise-head {
    flex-direction: column;
  }

  .exercise-mode {
    width: 100%;
  }

  .tense-card {
    border-right: 0;
  }
}
