:root {
  color-scheme: light;
  --bg: #f8f7f3;
  --ink: #1c1c1a;
  --muted: #6f706c;
  --line: #dfddd5;
  --surface: #ffffff;
  --accent: #276f5b;
  --accent-soft: #e4f1ec;
  --wrong: #9b3f32;
  --wrong-soft: #f7e6e2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

.practice-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  width: min(880px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
  font-weight: 700;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat {
  min-width: 78px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  border-radius: 8px;
  padding: 8px 10px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

#reset-button {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
}

#reset-button:hover {
  border-color: #bebcaf;
}

.practice-controls {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.list-filter-label {
  display: grid;
  gap: 5px;
  min-width: 190px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

#list-filter {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

#manage-lists-button,
.modal-actions button,
#copy-prompt-button,
#clear-lists-button,
#export-lists-button,
.file-import-button,
.saved-list-delete {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

#manage-lists-button:hover,
.modal-actions button:hover,
#copy-prompt-button:hover,
#clear-lists-button:hover,
#export-lists-button:hover,
.file-import-button:hover,
.saved-list-delete:hover {
  border-color: #bebcaf;
}

.drill-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.drill-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

.drill-tab:hover {
  border-color: #bebcaf;
}

.drill-tab.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.drill-tab:disabled {
  border-color: var(--line);
  background: #f0efea;
  color: #aaa79d;
  cursor: not-allowed;
}

.drill-tab:disabled:hover {
  border-color: var(--line);
}

.history-panel {
  display: flex;
  align-items: flex-end;
  min-height: 0;
  overflow: hidden;
}

.history-list {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(28, 28, 26, 0.08);
  padding: 0 0 8px;
  font-size: 0.98rem;
  line-height: 1.4;
}

.history-prompt {
  min-width: 0;
}

.history-answer {
  flex: none;
  font-weight: 700;
}

.current-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
  box-shadow: 0 12px 32px rgba(35, 32, 24, 0.08);
}

.exercise-meta {
  display: inline-block;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 9px;
}

.exercise-prompt {
  margin-top: 16px;
  min-height: 42px;
  font-size: 2rem;
  line-height: 1.2;
  font-weight: 700;
}

.hint-display {
  min-height: 28px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 700;
}

.answer-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 18px;
}

.answer-label {
  flex: 1;
  min-width: 0;
}

#answer-input {
  width: 100%;
  min-height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  font-size: 1.25rem;
  outline: none;
}

#answer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(39, 111, 91, 0.14);
}

#answer-input.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong-soft);
}

.hint-button {
  width: 58px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 800;
}

.hint-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.hint-button:disabled {
  cursor: default;
  color: var(--muted);
  background: #f1f0eb;
}

.feedback {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--wrong);
  font-size: 0.92rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(28, 28, 26, 0.38);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 20px;
  box-shadow: 0 22px 60px rgba(35, 32, 24, 0.22);
}

.modal-header,
.prompt-header,
.modal-actions,
.section-heading-row,
.list-file-actions,
.saved-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-header h2,
.prompt-header h3,
.section-heading-row h3,
.format-help h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1.1rem;
}

.section-heading-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.saved-lists-section {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfaf6;
}

.saved-lists {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.saved-list-row {
  border-top: 1px solid rgba(28, 28, 26, 0.08);
  padding-top: 8px;
}

.saved-list-meta {
  display: grid;
  gap: 3px;
}

.saved-list-name {
  font-weight: 700;
}

.saved-list-counts {
  color: var(--muted);
  font-size: 0.82rem;
}

.saved-list-delete {
  min-height: 32px;
  color: var(--wrong);
}

.saved-list-delete:disabled,
#clear-lists-button:disabled,
#export-lists-button:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: #f1f0eb;
}

.list-file-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 14px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.field-label {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.field-label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.text-field,
.import-area,
.prompt-area {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.import-area,
.prompt-area {
  resize: vertical;
  line-height: 1.4;
}

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

.format-help {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfaf6;
}

.format-help p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.format-help > p {
  grid-column: 1 / -1;
}

code {
  border-radius: 5px;
  background: #efeee8;
  color: var(--ink);
  padding: 1px 5px;
  font-size: 0.9em;
}

.prompt-box {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfaf6;
}

.prompt-area {
  margin-top: 12px;
  min-height: 190px;
}

.form-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--wrong);
  font-size: 0.9rem;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

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

@media (max-width: 960px) {
  body {
    overflow: hidden;
  }

  .practice-shell {
    width: min(100% - 20px, 880px);
    height: 100dvh;
    min-height: 100svh;
    grid-template-rows: auto minmax(110px, 1fr) auto;
    gap: 8px;
    overflow: hidden;
    padding: max(8px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
  }

  .top-bar {
    align-items: center;
    display: flex;
    gap: 10px;
  }

  h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    display: none;
  }

  .stats {
    flex: none;
    gap: 6px;
    justify-content: flex-start;
  }

  .stat {
    min-width: 50px;
    padding: 5px 7px;
  }

  .stat-label {
    font-size: 0.64rem;
  }

  .stat strong {
    font-size: 0.95rem;
    margin-top: 2px;
  }

  #reset-button {
    height: 38px;
    padding: 0 10px;
  }

  .history-panel {
    align-items: flex-end;
    min-height: 72px;
    overflow: hidden;
  }

  .history-list {
    gap: 5px;
  }

  .history-item {
    font-size: 0.95rem;
    padding-bottom: 5px;
  }

  .current-card {
    padding: 10px;
  }

  .practice-controls {
    align-items: end;
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
  }

  .list-filter-label {
    flex: 1;
    min-width: 0;
  }

  .list-filter-label span {
    display: none;
  }

  #list-filter,
  #manage-lists-button {
    min-height: 30px;
    padding: 0 8px;
  }

  .drill-tabs {
    flex-wrap: nowrap;
    gap: 5px;
    margin-bottom: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

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

  .drill-tab {
    flex: 0 0 auto;
    font-size: 0.9rem;
    min-height: 30px;
    padding: 0 8px;
  }

  .exercise-meta {
    font-size: 0.72rem;
    padding: 4px 8px;
  }

  .exercise-prompt {
    font-size: 1.55rem;
    margin-top: 8px;
    min-height: 30px;
  }

  .hint-display {
    min-height: 20px;
    margin-top: 4px;
  }

  #answer-input {
    font-size: 1rem;
    min-height: 44px;
    padding: 0 12px;
  }

  .answer-row {
    gap: 8px;
    margin-top: 8px;
  }

  .hint-button {
    min-height: 44px;
    width: 44px;
  }

  .feedback {
    margin-top: 6px;
    min-height: 18px;
  }

  .site-footer {
    display: none;
  }

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

  .section-heading-row,
  .saved-list-row,
  .list-file-actions,
  .modal-actions {
    align-items: stretch;
    display: grid;
  }

  .format-help {
    grid-template-columns: 1fr;
  }

  body.keyboard-open .practice-shell {
    grid-template-rows: minmax(105px, 1fr) auto;
    padding-top: 6px;
  }

  body.keyboard-open .top-bar,
  body.keyboard-open .site-footer {
    display: none;
  }

  body.keyboard-open .history-panel {
    min-height: 120px;
  }

  body.keyboard-open .current-card {
    border-radius: 0;
    border-width: 1px 0 0;
    box-shadow: none;
    padding: 8px 0 6px;
  }

  body.keyboard-open .practice-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    padding: 0 2px;
  }

  body.keyboard-open .drill-tabs {
    margin-bottom: 6px;
    padding: 0 2px 2px;
  }

  body.keyboard-open .exercise-meta,
  body.keyboard-open .exercise-prompt,
  body.keyboard-open .hint-display,
  body.keyboard-open .answer-row,
  body.keyboard-open .feedback {
    margin-left: 2px;
    margin-right: 2px;
  }

  body.keyboard-open .exercise-prompt {
    font-size: 1.35rem;
    margin-top: 6px;
  }
}
