:root {
  --bg: #e8eef3;
  --ink: #13212b;
  --muted: #617789;
  --line: #c6d5e1;
  --card: #ffffff;
  --primary: #0a80c2;
  --primary-strong: #06679b;
  --ok: #1e9f61;
  --danger: #c74646;
  --soft: #f2f7fb;
  --radius: 16px;
  --shadow: 0 10px 26px rgba(8, 34, 51, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(10, 128, 194, 0.1), transparent 25%),
    radial-gradient(circle at 95% 20%, rgba(28, 159, 97, 0.08), transparent 30%),
    var(--bg);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.topbar {
  background: linear-gradient(90deg, var(--primary-strong), var(--primary));
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 14px rgba(4, 31, 46, 0.24);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 16px;
  height: 16px;
  transform: rotate(45deg);
  background: #fff;
  border-radius: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-strong);
  font-weight: 700;
  padding: 7px 12px;
  min-width: 90px;
}

.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 16px 30px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 14px;
}

.app-version {
  margin-top: 10px;
  text-align: center;
  font-size: 0.78rem;
  color: #6f8291;
}

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

.panel h1 {
  font-size: clamp(1.6rem, 2.8vw, 2.1rem);
}

.panel h2 {
  font-size: clamp(1.3rem, 2.1vw, 1.7rem);
}

.panel > p {
  margin-top: 10px;
  color: #243744;
  line-height: 1.55;
}

.bank-order-info {
  margin-top: 6px;
  font-size: 0.9rem;
  color: #567184;
  font-weight: 600;
}

.field-label {
  margin-top: 16px;
  display: block;
  font-weight: 700;
}

.text-input,
.select-input {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #a7bfce;
  border-radius: 10px;
  font: inherit;
  padding: 11px 12px;
  background: #f9fdff;
}

.text-input:focus,
.select-input:focus {
  outline: 2px solid #8ecded;
  border-color: var(--primary);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(120deg, var(--primary), #1aa5dd);
  color: #fff;
}

.btn-muted {
  background: #6d8798;
  color: #fff;
}

.btn-ghost {
  background: #eef4f8;
  color: #375265;
  border: 1px solid #b8c9d6;
}

#startBtn {
  margin-top: 18px;
}

#openBankBtn {
  margin-top: 8px;
}

.helper-text {
  margin-top: 12px;
  color: #5f7587;
  font-size: 0.95rem;
}

.helper-text.compact {
  margin-top: 8px;
}

.topic-picker {
  margin-top: 10px;
}

.topic-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topic-picker-actions {
  display: flex;
  gap: 6px;
}

.topic-picker-actions .btn {
  padding: 6px 10px;
  font-size: 0.88rem;
}

.topic-select-wrap {
  margin-top: 8px;
  border: 1px solid #d1dce6;
  border-radius: 10px;
  background: #f9fdff;
  max-height: 180px;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.topic-select-item {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "check label"
    "check ids";
  gap: 8px;
  align-items: start;
  font-size: 0.92rem;
  padding: 6px 4px;
}

.topic-select-item input {
  grid-area: check;
  margin-top: 2px;
}

.topic-label {
  grid-area: label;
  font-weight: 700;
}

.topic-ids {
  grid-area: ids;
  color: #547086;
  font-size: 0.82rem;
  line-height: 1.35;
  word-break: break-word;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-wrap {
  margin-top: 12px;
  max-height: 65vh;
  overflow: auto;
  border: 1px solid #d1dce6;
  border-radius: 12px;
}

.history-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 8px;
}

.history-controls .text-input,
.history-controls .select-input {
  margin-top: 0;
}

.bank-panel {
  margin-top: 14px;
}

.bank-head {
  align-items: flex-start;
}

.bank-controls {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  width: min(900px, 100%);
}

.bank-controls .text-input,
.bank-controls .select-input {
  margin-top: 0;
}

.bank-wrap {
  margin-top: 10px;
  border: 1px solid #d1dce6;
  border-radius: 12px;
  max-height: 58vh;
  overflow: auto;
  background: #fff;
}

.bank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.bank-table th,
.bank-table td {
  border-bottom: 1px solid #dbe5ed;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.bank-table thead th {
  background: #eff5f9;
  position: sticky;
  top: 0;
}

.bank-id-col {
  white-space: nowrap;
  font-weight: 700;
}

.bank-type-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf6fc;
  border: 1px solid #bcd4e6;
  color: #36556a;
  white-space: nowrap;
}

.bank-preview {
  margin-top: 6px;
}

.bank-preview summary {
  cursor: pointer;
  color: #1a5f86;
  font-weight: 600;
}

.bank-preview-content {
  margin-top: 8px;
  border: 1px solid #c9dbe8;
  border-radius: 8px;
  background: #f8fcff;
  padding: 8px;
  display: grid;
  gap: 8px;
  line-height: 1.45;
}

.bank-preview-list {
  margin: 0;
  padding-left: 20px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid #dbe5ed;
  padding: 8px;
  text-align: left;
  white-space: nowrap;
}

.history-table thead th {
  background: #eff5f9;
  position: sticky;
  top: 0;
}

.empty-history {
  padding: 14px;
  color: #5a7386;
}

.history-source {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.35;
}

.history-source-local {
  background: #fff5e8;
  border: 1px solid #f0c486;
  color: #82511a;
}

.history-source-cloud {
  background: #ecf7ef;
  border: 1px solid #8fcca1;
  color: #1f6a34;
}

.history-name-btn {
  border: 1px solid #8ebad8;
  background: #f4fbff;
  color: #0b4f7a;
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  cursor: pointer;
}

.history-name-btn:hover {
  background: #e7f4ff;
}

.history-name-btn.active {
  background: #d7edff;
  border-color: #4d9ad0;
}

.history-detail-panel {
  margin-top: 10px;
  border: 1px solid #c9dbe8;
  border-radius: 10px;
  padding: 10px;
  background: #f8fcff;
}

.history-detail-head {
  margin-bottom: 6px;
  color: #1a4f73;
}

.history-detail-ids {
  margin: 0 0 8px;
  color: #4f6f83;
}

.history-detail-table-wrap {
  overflow-x: auto;
}

.history-detail-panel .history-table th,
.history-detail-panel .history-table td {
  white-space: normal;
  vertical-align: top;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 35, 51, 0.45);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(1200px, 96vw);
  max-height: 90vh;
  border: 1px solid #c6d7e4;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 44px rgba(18, 44, 63, 0.22);
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 12px 14px;
  border-bottom: 1px solid #dbe5ed;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-head h3 {
  margin: 0;
}

.modal-body {
  padding: 12px 14px 14px;
  overflow: auto;
}

.modal-body .history-table th,
.modal-body .history-table td {
  white-space: normal;
  vertical-align: top;
}

body.modal-open {
  overflow: hidden;
}

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

.quiz-meta {
  display: flex;
  gap: 8px;
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.context-text {
  margin-top: 10px;
  display: grid;
  gap: 10px;
  line-height: 1.55;
}

.context-visual {
  margin-top: 12px;
  border: 1px solid #cbd9e4;
  border-radius: 12px;
  background: #f8fcff;
  min-height: 220px;
  padding: 12px;
  overflow: auto;
}

.context-visual.is-empty {
  display: none;
}

.question-prompt {
  margin-top: 10px;
  font-size: 1.08rem;
  line-height: 1.45;
  font-weight: 700;
}

.answer-form {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.option-card {
  border: 1px solid #bfd0dd;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.option-card:hover {
  background: #f4fbff;
  border-color: var(--primary);
}

.option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: #8ea2b1;
}

.option-text {
  flex: 1;
}

.inline-info {
  min-height: 20px;
  margin-top: 12px;
  color: #527083;
  font-weight: 600;
}

.match-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  align-items: center;
}

.match-row select {
  border: 1px solid #9fb7c8;
  border-radius: 8px;
  padding: 8px;
  font: inherit;
}

.table-visual {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table-visual th,
.table-visual td {
  border: 1px solid #9fc0d6;
  padding: 5px;
  text-align: center;
}

.flowchart-visual {
  width: 100%;
  height: auto;
  display: block;
}

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

.badge {
  border: 1px solid #afc4d5;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  font-weight: 600;
}

.algo-card {
  border: 1px solid #d8cc9f;
  border-radius: 12px;
  background: #f6edcf;
  padding: 12px;
  overflow: auto;
}

.algo-card pre {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: 1rem;
  line-height: 1.6;
  white-space: pre;
}

.nav-row {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
}

.result-summary {
  margin-top: 12px;
  font-size: 1.08rem;
  line-height: 1.6;
}

.result-details {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.result-topic-summary {
  display: grid;
  gap: 8px;
}

.detail-chip {
  background: #eef6fb;
  border: 1px solid #c5d7e3;
  border-radius: 10px;
  padding: 8px 10px;
}

.result-correction-title {
  margin-top: 8px;
  font-size: 1.15rem;
}

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

.result-question-item {
  border: 1px solid #cad8e3;
  border-radius: 10px;
  background: #f9fcff;
  padding: 10px;
}

.result-question-item.correct {
  border-color: #9cd1b6;
  background: #f3fbf7;
}

.result-question-item.wrong {
  border-color: #e2b4b4;
  background: #fff8f8;
}

.result-question-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.result-question-status {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.result-question-status.correct {
  background: #ddf3e8;
  color: #1f7f50;
}

.result-question-status.wrong {
  background: #f8e2e2;
  color: #9d3030;
}

.result-question-topic {
  margin-top: 6px;
  font-size: 0.9rem;
  color: #4d697b;
  font-weight: 600;
}

.result-question-prompt {
  margin-top: 6px;
  line-height: 1.45;
}

.result-question-answers {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-answer-label {
  margin: 0 0 4px 0;
  font-weight: 700;
}

.result-answer-list {
  margin: 0;
  padding-left: 18px;
}

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

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

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

@media (max-width: 1100px) {
  .setup-grid,
  .cards {
    grid-template-columns: 1fr;
  }

  .result-question-answers {
    grid-template-columns: 1fr;
  }

  .bank-controls {
    grid-template-columns: 1fr;
  }

  .history-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .layout {
    padding: 12px 10px 20px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand span {
    font-size: 0.95rem;
  }

  .panel {
    padding: 14px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .match-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
