/* Components: breadcrumbs, buttons, badges, cards and grids, term cards,
   panels, formulas, callouts, tables, chips, tooltips, toast, empty states,
   form fields, results, answer options, progress bars and the score ring. */

/* ------------------------------------------------------------------ breadcrumbs */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.crumbs a {
  color: var(--muted);
}

.crumbs a:hover {
  color: var(--primary-text);
}

.crumbs .sep {
  opacity: 0.5;
}

.crumbs .cur {
  color: var(--text);
  font-weight: 600;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, filter 0.15s, transform 0.15s;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  color: var(--primary-text);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

/* The site's primary action: the brand gradient with white text in both themes. */
.btn-primary {
  border-color: transparent;
  background: var(--brand-gradient);
  color: var(--on-btn);
  box-shadow: 0 10px 30px -14px color-mix(in srgb, var(--btn-b) 70%, transparent);
}

.btn-primary:hover {
  border-color: transparent;
  color: var(--on-btn);
  filter: brightness(1.1);
  box-shadow: 0 14px 36px -14px color-mix(in srgb, var(--btn-b) 85%, transparent);
}

.btn-accent {
  border-color: var(--ok);
  background: var(--ok);
  color: var(--ok-ink);
}

.btn-accent:hover {
  color: var(--ok-ink);
  filter: brightness(1.08);
}

.btn-soft {
  border-color: transparent;
  background: var(--primary-soft);
  color: var(--primary-text);
}

.btn-soft:hover {
  filter: brightness(0.97);
}

.btn-sm {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 0.84rem;
}

.btn-lg {
  min-height: 48px;
  padding: 11px 22px;
  border-radius: var(--r-md);
  font-size: 1rem;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.on {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

.btn.fav-on {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn-text);
}

.btn.fav-on .ic {
  fill: var(--amber);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.btn-row-center {
  justify-content: center;
}

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-accent { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-muted { background: var(--surface-3); color: var(--text-2); }

.badge-mono {
  font-family: var(--mono);
  direction: ltr;
}

/* ------------------------------------------------------------------ cards & grids */

.card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur), border-color var(--dur);
}

.card-link {
  display: block;
  color: inherit;
  cursor: pointer;
}

.card-link:hover {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  box-shadow: var(--shadow-glow);
  color: inherit;
  text-decoration: none;
  transform: translateY(-3px);
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

/* ------------------------------------------------------------------ term card */

.tcard {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
}

.tcard .top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.tcard .idx {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.tcard .ar {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.45;
}

.tcard .en {
  display: block;
  color: var(--primary-text);
  font-family: var(--mono);
  font-size: 0.8rem;
  direction: ltr;
  text-align: right;
}

.tcard .def {
  flex: 1;
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-2);
  font-size: 0.9rem;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.tcard .foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}

.tcard .state {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-inline-start: auto;
  color: var(--muted);
}

.tcard .state .ic { width: 16px; height: 16px; }
.tcard .state .v { color: var(--ok); }
.tcard .state .f { color: var(--amber); fill: var(--amber); }

.tcard.done {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
}

.tcard.done .idx {
  background: var(--ok-soft);
  color: var(--ok);
}

/* ------------------------------------------------------------------ panels (term sections) */

.panel {
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-sm);
}

.panel-h {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.panel-h:hover {
  background: var(--surface-2);
}

/* The header fills a clipped panel, so its focus ring is drawn inside. */
.panel-h:focus-visible {
  box-shadow: var(--focus-ring-inset);
}

.panel-h .ic { color: var(--primary); }

.panel-h .chev {
  margin-inline-start: auto;
  color: var(--muted);
  transition: transform 0.2s;
}

.panel.collapsed .chev { transform: rotate(-90deg); }
.panel.collapsed .panel-b { display: none; }

.panel-b {
  padding: 2px 18px 18px;
  color: var(--text-2);
}

.panel-b p,
.panel-b li {
  color: var(--text-2);
}

.panel-simple {
  border-color: color-mix(in srgb, var(--ok) 40%, var(--border));
  background: linear-gradient(180deg, var(--ok-soft), var(--surface) 60%);
}

.panel-simple .panel-h .ic { color: var(--ok); }

.panel-simple .panel-b {
  color: var(--text);
  font-size: 1.05rem;
}

.panel-shark {
  border-color: color-mix(in srgb, var(--info) 45%, var(--border));
}

.panel-shark .panel-h .ic { color: var(--info); }

/* ------------------------------------------------------------------ formula */

.formula {
  margin: 10px 0;
  padding: 12px 16px;
  overflow-x: auto;
  border: 1px dashed var(--border-2);
  border-radius: var(--r-md);
  background: var(--code-surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.8;
  direction: ltr;
  text-align: left;
  white-space: pre;
}

/* ------------------------------------------------------------------ callouts */

/* House callouts: a tinted card whose title takes the callout's colour. Note = indigo, warn = amber, tip = green. */
.co {
  --co-ink: var(--primary-text);
  --co-bg: var(--primary-soft);
  --co-line: color-mix(in srgb, var(--primary) 24%, transparent);
  position: relative;
  margin: 12px 0;
  padding: 12px 16px;
  border: 1px solid var(--co-line);
  border-radius: var(--r-md);
  background: var(--co-bg);
  color: var(--text);
}

.co p:last-child { margin-bottom: 0; }

.co.warn {
  --co-ink: var(--warn-text);
  --co-bg: var(--warn-soft);
  --co-line: color-mix(in srgb, var(--warn) 30%, transparent);
}

.co.tip {
  --co-ink: var(--ok);
  --co-bg: var(--ok-soft);
  --co-line: color-mix(in srgb, var(--ok) 28%, transparent);
}

.co.danger {
  --co-ink: var(--danger-text);
  --co-bg: var(--danger-soft);
  --co-line: color-mix(in srgb, var(--danger) 30%, transparent);
}

.co .co-t {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--co-ink);
  font-weight: 700;
}

/* ------------------------------------------------------------------ tables */

.tbl-wrap {
  margin: 12px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}

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

th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  text-align: start;
  white-space: nowrap;
}

td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
}

/* The house highlighter marks the row under the pointer. */
tr:hover td {
  background: var(--highlight-wash);
}

td .num,
th .num {
  white-space: nowrap;
}

.tbl-num td:not(:first-child),
.tbl-num th:not(:first-child) {
  direction: ltr;
  font-variant-numeric: tabular-nums;
  text-align: left;
  white-space: nowrap;
}

/* A subtotal row (the profit ladder's rungs). */
.row-key {
  background: var(--primary-soft);
  font-weight: 700;
}

.pos { color: var(--ok); font-weight: 700; }
.neg { color: var(--danger-text); font-weight: 700; }

/* ------------------------------------------------------------------ chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip:hover {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  color: var(--primary-text);
  text-decoration: none;
}

.chip.on {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

.chip .en {
  font-family: var(--mono);
  font-size: 0.76rem;
  direction: ltr;
  unicode-bidi: isolate;
}

/* ------------------------------------------------------------------ term links & tooltip */

.tl {
  border-bottom: 1px dotted var(--primary);
  color: var(--primary-text);
  text-decoration: none;
  cursor: help;
  unicode-bidi: isolate;
}

.tl:hover {
  border-radius: 3px;
  background: var(--highlight-wash);
  text-decoration: none;
}

#tooltip {
  position: fixed;
  z-index: 100;
  max-width: 300px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--paper);
  font-size: 0.82rem;
  line-height: 1.6;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
}

#tooltip.show {
  opacity: 1;
  transform: none;
}

#tooltip b {
  display: block;
  font-size: 0.86rem;
}

#tooltip .en {
  display: block;
  font-family: var(--mono);
  font-size: 0.74rem;
  direction: ltr;
  opacity: 0.8;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: 200;
  max-width: min(92vw, 460px);
  padding: 10px 18px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------------ empty state */

.empty {
  padding: 50px 20px;
  color: var(--muted);
  text-align: center;
}

.empty .ic {
  width: 44px;
  height: 44px;
  margin-bottom: 10px;
  opacity: 0.5;
}

/* ------------------------------------------------------------------ form fields */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-2);
  font-size: 0.86rem;
  font-weight: 600;
}

.field label .en {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 500;
  direction: ltr;
}

.field .in {
  position: relative;
}

/* Numbers read left to right; the unit sits in the right-hand padding. */
.field input,
.field select {
  width: 100%;
  height: 44px;
  padding: 0 60px 0 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: left;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.field .unit {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  pointer-events: none;
  transform: translateY(-50%);
}

.field input.ok {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.field input.bad {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.field .hint {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ------------------------------------------------------------------ result & options */

.result {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--r-md);
}

.result.ok {
  border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
  background: var(--ok-soft);
}

.result.bad {
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: var(--danger-soft);
}

.result .t {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 700;
}

.result.ok .t { color: var(--ok); }
.result.bad .t { color: var(--danger-text); }

.opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  margin-bottom: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  line-height: 1.7;
  text-align: start;
  transition: border-color 0.15s, background 0.15s;
}

.opt:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.opt .k {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 700;
}

.opt.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.opt.correct .k {
  background: var(--ok);
  color: var(--ok-ink);
}

.opt.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.opt.wrong .k {
  background: var(--danger);
  color: var(--bad-ink);
}

.opt:disabled { cursor: default; }
.opt:disabled:not(.correct):not(.wrong) { opacity: 0.6; }

/* ------------------------------------------------------------------ progress bar & score ring */

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--surface-3);
}

/* Fills from the right (RTL start) in the brand gradient: indigo → cyan → emerald. */
.bar > i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(270deg, var(--grad-a), var(--grad-b) 55%, var(--grad-c));
  transition: width 0.5s var(--ease);
}

.score-ring {
  --p: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 130px;
  height: 130px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: conic-gradient(var(--grad-a), var(--grad-b) calc(var(--p) * 0.5%), var(--grad-c) calc(var(--p) * 1%), var(--surface-3) 0);
}

.score-ring::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: var(--surface);
}

.score-ring span {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
}
