/* ── Palette
   #000000  black      — text, active states
   #115035  forest     — header, primary accent, correct score
   #ff9e97  coral      — incorrect highlights
   #f6cb4c  yellow     — badges
   #a3b4fc  lavender   — focus rings, hover accents
   #eeeeee  light gray — page background
──────────────────────────────────────────── */

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Avenir', 'Avenir Next', 'Century Gothic', Futura, sans-serif;
  font-size: 15px;
  background: #FCFCFC;
  color: #000000;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: #115035;
  color: #fff;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 200;
}

header h1 {
  font-family: 'Optima', 'Optima Nova', Candara, 'Gill Sans', serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ── Main layout ── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* ── Direction toggle (segmented control) ── */
.direction-toggle {
  display: flex;
  border: 1px solid #ccc;
  border-radius: 8px;
  overflow: hidden;
}

.btn-dir {
  padding: 7px 14px;
  background: #fff;
  border: none;
  border-right: 1px solid #ccc;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-dir:last-child { border-right: none; }
.btn-dir.active { background: #3E7AF3; color: #fff; }
.btn-dir:not(.active):not(:disabled):hover { background: #e8e8e8; color: #000; }
.btn-dir:disabled { opacity: 0.35; cursor: default; }

/* ── Drill category title ── */
.drill-title {
  font-family: 'Optima', 'Optima Nova', Candara, 'Gill Sans', serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 6px 0;
  color: #222;
}

/* ── Action buttons bar ── */
.controls-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: default; }
.btn:not(:disabled):hover { filter: brightness(0.93); }
.btn:not(:disabled):active { filter: brightness(0.86); }

.btn-primary   { background: #9AEAC7; color: #115035; border: 1px solid #115035; }
.btn-secondary { background: #ddd; color: #000; }
.btn-ghost     { background: #f6cb4c; color: #000; border: 1px solid #c9a030; }

/* ── Score ── */
.score {
  margin-left: auto;
  font-size: 0.95rem;
  font-weight: 600;
  color: #000;
  white-space: nowrap;
}
.score .correct-count { color: #115035; }
.score .total-count   { color: #777; }

/* ── Placeholder ── */
.placeholder {
  text-align: center;
  color: #777;
  padding: 60px 0;
  font-size: 1rem;
}

/* ── Edit / Save tab above table ── */
.table-tab-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding-right: 14px; /* clear the table's rounded corner */
}
.action-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: 6px 6px 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid;
  border-bottom: none;
  position: relative;
  bottom: -1px;
  z-index: 1;
  transition: filter 0.15s;
}
.action-tab:hover { filter: brightness(0.93); }
.edit-tab { background: #eeeeee; color: #444; border-color: #999; }
.save-tab { background: #9AEAC7; color: #115035; border-color: #115035; }

/* ── Table wrapper ── */
.table-wrapper {
  overflow: clip; /* clips border-radius corners without creating a scroll container, so sticky thead works */
  border-radius: 12px;
  border: 1px solid #ccc;
  background: #fff;
}

/* Inner scroll div used for conjugation tables on mobile */
.table-scroll-inner {
  overflow-x: auto;
}

/* ── Drill table ── */
table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  border-bottom: none;
}

th {
  padding: 7px 10px;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  white-space: nowrap;
  background: #1645A2;
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  padding: 4px 10px;
  border-bottom: 1px solid #e8e8e8;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

@media (hover: hover) {
  tr:hover td { background: #EBEFFE; }
  table tr.row-incorrect:hover td { background: rgba(255, 158, 151, 0.4); }
}

/* Row states */
table tr.row-incorrect td { background: rgba(255, 158, 151, 0.25); }

/* Badge column */
td.col-badge, th.col-badge-hd {
  width: 60px;
  text-align: center;
}

/* Number column */
td.col-num, th.col-num {
  width: 40px;
  color: #aaa;
  font-size: 0.8rem;
  text-align: center;
}

/* Answer input */
.answer-input {
  width: 100%;
  min-width: 120px;
  padding: 3px 7px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s;
}

.answer-input:focus {
  outline: none;
  border-color: #a3b4fc;
  box-shadow: 0 0 0 2px rgba(163, 180, 252, 0.35);
}

tr.row-incorrect .answer-input {
  border-color: #ff9e97;
  background: rgba(255, 158, 151, 0.12);
}

/* Sortable column headers */
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover,
th.col-num:hover { color: #fff; background: #3E7AF3; cursor: pointer; }

th.sortable .sort-arrow {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.7rem;
  opacity: 0.45;
}
th.sortable.sort-asc .sort-arrow,
th.sortable.sort-desc .sort-arrow { opacity: 1; color: #f6cb4c; }

/* Icon buttons inside table headers */
.btn-eye,
.btn-shuffle-header {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 3px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  vertical-align: middle;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-eye { margin-left: 6px; }
.btn-eye:hover,
.btn-shuffle-header:hover { color: #fff; background: rgba(255,255,255,0.2); }

/* Result cell */
.col-result {
  width: 36px;
  text-align: center;
  font-size: 1rem;
}

/* Answer column */
td[data-answer] {
  font-style: italic;
  color: #555;
  font-size: 0.95rem;
}

/* Hidden when answers not revealed, or the row is already correct */
table.hide-answers [data-answer],
[data-answer].answer-locked {
  color: transparent;
  user-select: none;
}

/* Try Again label */
.try-again {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b03a3a;
  white-space: nowrap;
  cursor: pointer;
}
.try-again:hover { text-decoration: underline; }

/* Input cell with badge */
.input-with-badge { display: flex; align-items: center; gap: 8px; }
.input-with-badge .answer-input { flex: 1; min-width: 0; width: auto; }

/* Tag badges (ending, gender) */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Fallback for custom badge values */
.badge { background: #eeeeee; color: #555; }

/* Verb ending colors */
.badge-ar { background: #d1fae5; color: #115035; }
.badge-ir { background: #fde8e8; color: #c0356e; }
.badge-er { background: #fef9c3; color: #926a00; }

/* Gender colors */
.badge-el { background: #dbeafe; color: #1d4ed8; }
.badge-la { background: #fde8e8; color: #c0356e; }

/* ── Language toggle ── */
#landing { max-width: 900px; margin: 0 auto; padding: 32px 24px; }

.lang-toggle-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}

.btn-lang {
  padding: 8px 18px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-lang.active { background: #c8e6d4; color: #115035; border-color: #90c9aa; }
.btn-lang:not(.active):hover { background: #f0f0f0; color: #333; }

/* ── Landing page ── */

.landing-section { margin-bottom: 36px; }

.landing-section h2 {
  font-family: 'Optima', 'Optima Nova', Candara, 'Gill Sans', serif;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #115035;
  margin-bottom: 12px;
}

.category-buttons { display: flex; flex-wrap: wrap; gap: 10px; }

.btn-category {
  padding: 12px 20px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #ccc;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  color: #000;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

/* ── Section color themes ── */

/* Lavender — Vocabulary */
.section-lavender h2                      { color: #4a5ab5; }
.section-lavender .btn-category           { background: #f0f2ff; border-color: #a3b4fc; color: #3d4fa0; }
.section-lavender .btn-category:hover     { background: #a3b4fc; border-color: #a3b4fc; color: #000; box-shadow: 0 2px 10px rgba(163,180,252,0.45); }

/* Green — Verbs */
.section-green h2                         { color: #115035; }
.section-green .btn-category              { background: #eaf4ef; border-color: #115035; color: #115035; }
.section-green .btn-category:hover        { background: #115035; border-color: #115035; color: #fff; box-shadow: 0 2px 10px rgba(17,80,53,0.3); }

/* Coral — Description */
.section-coral h2                         { color: #c04848; }
.section-coral .btn-category              { background: #fff2f1; border-color: #ff9e97; color: #b03a3a; }
.section-coral .btn-category:hover        { background: #ff9e97; border-color: #ff9e97; color: #000; box-shadow: 0 2px 10px rgba(255,158,151,0.45); }

/* Yellow — Functional Words */
.section-yellow h2                        { color: #8a6000; }
.section-yellow .btn-category             { background: #fffbec; border-color: #f6cb4c; color: #7a5400; }
.section-yellow .btn-category:hover       { background: #f6cb4c; border-color: #f6cb4c; color: #000; box-shadow: 0 2px 10px rgba(246,203,76,0.45); }

/* Blue — Conjugation */
.section-blue h2                          { color: #1645A2; }
.section-blue .btn-category              { background: #eef2ff; border-color: #3E7AF3; color: #1645A2; }
.section-blue .btn-category:hover        { background: #3E7AF3; border-color: #3E7AF3; color: #fff; box-shadow: 0 2px 10px rgba(62,122,243,0.35); }

/* ── Your Lists section ── */
.section-black h2                     { color: #000; }
.section-black .btn-category          { background: #f5f5f5; border-color: #999; color: #000; }
.section-black .btn-category:hover    { background: #000; color: #fff; border-color: #000; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.section-black .btn-new-list          { background: transparent; border-style: dashed; border-color: #aaa; color: #555; }
.section-black .btn-new-list:hover    { background: #000; color: #fff; border-style: solid; border-color: #000; }

.custom-list-btn-group                { display: flex; align-items: stretch; }
.custom-list-btn-group .btn-category  { border-radius: 10px 0 0 10px; }
.btn-edit-list {
  display: flex; align-items: center; justify-content: center;
  padding: 0 10px;
  background: #f5f5f5; border: 1px solid #999; border-left: none;
  border-radius: 0 10px 10px 0;
  cursor: pointer; color: #777;
  transition: color 0.15s, background 0.15s;
}
.btn-edit-list:hover { color: #000; background: #e8e8e8; }

/* ── Edit view ── */
#edit-view {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

.edit-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.edit-title {
  font-family: 'Optima', 'Optima Nova', Candara, serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: #000;
}

.edit-name-row { margin-bottom: 20px; }

.edit-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  margin-bottom: 6px;
}

.edit-name-input {
  width: 100%;
  max-width: 420px;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}
.edit-name-input:focus {
  outline: none;
  border-color: #a3b4fc;
  box-shadow: 0 0 0 2px rgba(163,180,252,0.35);
}

.edit-table-wrapper { margin-bottom: 12px; }

/* Narrow columns in edit table (Ending, Gender) */
.col-edit-narrow { width: 80px; }
.col-edit-narrow .answer-input { min-width: 0; text-align: center; }

/* Delete row button */
.col-del { width: 36px; text-align: center; }
.btn-del-row {
  background: none; border: none;
  color: #bbb; font-size: 1.1rem;
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
  line-height: 1;
}
.btn-del-row:hover { color: #c04040; background: rgba(192,64,64,0.08); }

#edit-add-row { margin-bottom: 20px; }

.edit-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn-delete {
  margin-left: auto;
  background: transparent;
  color: #c04040;
  border: 1px solid #f5a0a0;
}
.btn-delete:not(:disabled):hover { filter: none; background: rgba(192,64,64,0.08); }

.edit-error {
  color: #c04040;
  font-size: 0.9rem;
  margin-top: 12px;
}

/* ── Responsive ── */
@media (max-width: 640px) {

  /* General layout */
  main  { padding: 10px 12px 160px; } /* bottom padding for fixed drill bar */
  #landing { padding: 20px 14px; }
  .controls-bottom { gap: 8px; }
  .score { margin-left: 0; width: 100%; text-align: right; }
  .btn     { padding: 8px 14px; font-size: 0.85rem; }
  .btn-dir { padding: 6px 11px; font-size: 0.8rem; }
  .btn-category { padding: 10px 14px; font-size: 0.9rem; }
  th, td { padding: 6px 8px; }

  /* Vocabulary table */
  #table-container { overflow-x: hidden; }
  table.drill-vocab { table-layout: fixed; width: 100%; }
  table.drill-vocab .col-num    { width: 28px; }
  table.drill-vocab .col-result { width: 28px; }
  table.drill-vocab .col-badge  { width: 44px; }
  /* Collapse hidden answer span so it doesn't inflate row height */
  table.drill-vocab.hide-answers .mob-correct,
  table.drill-vocab .mob-correct.answer-locked { display: none; }

  /* Mobile answer cell — typed answer + hidden correct answer stacked */
  .col-mob-answer, .col-prompt { word-break: break-word; overflow-wrap: break-word; }
  .mob-typed {
    display: block;
    color: #000;
    font-weight: 500;
  }
  .mob-correct {
    display: block;
    font-style: italic;
    color: #555;
    font-size: 0.9rem;
    margin-top: 2px;
  }

  /* Active row highlight */
  tbody tr.mob-active td                      { background: #eef1ff !important; }
  tbody tr.mob-active.row-incorrect td        { background: rgba(255,158,151,0.35) !important; }

  /* ✓ and ✕ icons in result column */
  .mob-check { color: #115035; font-weight: 700; font-size: 1rem; }
  .mob-retry { font-size: 1.1rem; font-weight: 700; }

  /* Conjugation: compact, horizontally scrollable */
  table.drill-conj th,
  table.drill-conj td { padding: 5px 8px; font-size: 0.82rem; }
  table.drill-conj .answer-input { min-width: 80px; }

  /* Edit view */
  #edit-view { padding: 16px 14px 260px; }
  .edit-table-wrapper { overflow: clip; }
  .col-edit-narrow { width: 60px; }
}

/* ── Mobile drill bar (fixed, always visible during drill) ── */
#mobile-drill-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 2px solid #a3b4fc;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.08);
  transition: border-top-color 0.2s, background 0.2s;
}
#mobile-drill-bar[data-result="correct"]   { border-top-color: #115035; background: #eaf4ef; }
#mobile-drill-bar[data-result="incorrect"] { border-top-color: #ff9e97; background: #fff4f3; }

.mob-bar-prompt {
  font-size: 1.05rem;
  font-weight: 600;
  color: #000;
}
.mob-bar-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.mob-bar-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #a3b4fc;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  outline: none;
}
.mob-bar-input:focus {
  border-color: #6b7ff0;
  box-shadow: 0 0 0 2px rgba(163,180,252,0.35);
}
.mob-bar-submit {
  padding: 10px 16px;
  background: #115035;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.mob-bar-submit:active { filter: brightness(0.85); }

/* ── Mobile edit bar (fixed, always visible in edit view on mobile) ── */
#mobile-edit-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: #fff;
  border-top: 2px solid #a3b4fc;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.08);
}

.mob-edit-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mob-edit-row-num {
  flex: 1;
  font-size: 0.8rem;
  color: #888;
}

.mob-edit-nav { display: flex; gap: 4px; }

.mob-edit-nav-btn {
  padding: 5px 11px;
  background: #eee;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
}
.mob-edit-nav-btn:active { filter: brightness(0.88); }

.mob-edit-action-btn {
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.mob-edit-action-btn:not(.mob-edit-del-btn) { background: #9AEAC7; color: #115035; border: 1px solid #115035; }
.mob-edit-del-btn                           { background: #ffe4e2; color: #9a1a1a; }
.mob-edit-action-btn:active { filter: brightness(0.88); }

.mob-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mob-edit-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mob-edit-label {
  width: 44px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #999;
}

.mob-edit-input {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid #ccc;
  border-radius: 7px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  outline: none;
}
.mob-edit-input:focus { border-color: #a3b4fc; box-shadow: 0 0 0 2px rgba(163,180,252,0.3); }
.mob-edit-badge-input { max-width: 90px; flex: none; }

.mob-edit-placeholder { color: #ccc; font-style: italic; }
