/* LINGO — component layer.
   Border, fill, radius and shadow are spent by role: a "card" is a real
   object, a "panel" is a quiet container, a "tile" is data. */

/* ======================================================================
   Buttons
   ====================================================================== */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-line: var(--line-2);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--r-pill);
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: var(--step-0);
  letter-spacing: -0.012em;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), background var(--t) var(--ease),
    border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), opacity var(--t) var(--ease);
  user-select: none;
}

.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px) scale(0.985); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.btn .icon { width: 18px; height: 18px; flex: none; }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--text-on-accent);
  --btn-line: transparent;
  box-shadow: 0 10px 30px -14px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-hot); box-shadow: 0 14px 38px -14px var(--accent-glow); }

.btn-ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-outline { --btn-bg: transparent; }
.btn-outline:hover { background: var(--surface); border-color: var(--line-lit); }

.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-line: rgba(255, 95, 87, 0.35); }
.btn-danger:hover { background: rgba(255, 95, 87, 0.1); }

.btn-lg { padding: 15px 28px; font-size: var(--step-1); }
.btn-sm { padding: 7px 14px; font-size: var(--step--1); }
.btn-block { display: flex; width: 100%; }
.btn-square { padding: 10px; border-radius: var(--r-sm); }

.btn-loading { color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--btn-fg);
  animation: spin 700ms linear infinite;
}

/* ======================================================================
   Surfaces
   ====================================================================== */

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}

/* Lit top edge — the single depth trick reused everywhere. */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--line-lit) 25%, var(--line-lit) 75%, transparent);
  opacity: 0.7;
  pointer-events: none;
}

.card-flat { background: var(--surface-inset); border-color: var(--line); }
.card-flat::before { display: none; }

.card-link {
  display: block;
  transition: transform var(--t) var(--ease), border-color var(--t) var(--ease),
    background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.card-link:hover {
  transform: translateY(-3px);
  border-color: var(--line-2);
  background: var(--surface-2);
  box-shadow: var(--shadow-2);
}

.panel {
  background: var(--surface-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tile-value {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tile-label {
  font-size: var(--step--1);
  color: var(--text-3);
}

.glass {
  background: rgba(22, 26, 34, 0.66);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line-2);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

/* ======================================================================
   Pills, badges, chips
   ====================================================================== */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}
.pill .icon { width: 14px; height: 14px; }
.pill-accent {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.pill-solid { background: var(--accent); border-color: transparent; color: var(--text-on-accent); font-weight: 600; }
.pill-ok { background: rgba(62, 224, 160, 0.1); border-color: rgba(62, 224, 160, 0.3); color: var(--ok); }
.pill-warn { background: rgba(255, 181, 71, 0.1); border-color: rgba(255, 181, 71, 0.3); color: var(--warn); }
.pill-danger { background: rgba(255, 95, 87, 0.1); border-color: rgba(255, 95, 87, 0.3); color: var(--danger); }
.pill-streak { background: rgba(255, 138, 61, 0.12); border-color: rgba(255, 138, 61, 0.32); color: var(--streak); }

.badge-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-2);
  background: rgba(16, 19, 25, 0.7);
  backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-2);
}
.badge-eyebrow .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-2);
  font-size: var(--step--1);
  font-weight: 500;
  transition: all var(--t) var(--ease);
}
.chip:hover { border-color: var(--line-lit); color: var(--text); background: var(--surface); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* CEFR level chip */
.lvl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 3px 9px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--lvl);
  background: color-mix(in srgb, var(--lvl) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--lvl) 34%, transparent);
}
.lvl-a1 { --lvl: var(--lvl-a1); }
.lvl-a2 { --lvl: var(--lvl-a2); }
.lvl-b1 { --lvl: var(--lvl-b1); }
.lvl-b2 { --lvl: var(--lvl-b2); }
.lvl-c1 { --lvl: var(--lvl-c1); }
.lvl-c2 { --lvl: var(--lvl-c2); }

/* ======================================================================
   Progress
   ====================================================================== */

.bar {
  position: relative;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 900ms var(--ease-out);
}
.bar-sm { height: 5px; }
.bar-lg { height: 12px; }
.bar-streak .bar-fill { background: linear-gradient(90deg, #d9641f, var(--streak)); }

.ring { display: block; transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); fill: none; }
.ring-fill {
  stroke: var(--accent);
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s var(--ease-out);
}
.ring-wrap { position: relative; display: inline-grid; place-items: center; }
.ring-center {
  position: absolute;
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.1;
}

.xp-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px 6px 9px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-weight: 700;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

/* ======================================================================
   Forms
   ====================================================================== */

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

.label {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.005em;
}

.input, .textarea, .select {
  width: 100%;
  padding: 12px 15px;
  background: var(--surface-inset);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--text);
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 110px; line-height: 1.6; }

.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a4abb8' stroke-width='2' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

.field-error { color: var(--danger); font-size: var(--step--1); }
.input[aria-invalid="true"] { border-color: rgba(255, 95, 87, 0.55); }

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
  font-size: var(--step--1);
  color: var(--text-2);
  line-height: 1.5;
}
.checkbox input {
  appearance: none;
  flex: none;
  width: 20px; height: 20px;
  margin: 0;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--surface-inset);
  display: grid;
  place-content: center;
  transition: all var(--t) var(--ease);
}
.checkbox input::after {
  content: "";
  width: 11px; height: 11px;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: var(--text-on-accent);
  transform: scale(0);
  transition: transform var(--t) var(--ease-spring);
}
.checkbox input:checked { background: var(--accent); border-color: var(--accent); }
.checkbox input:checked::after { transform: scale(1); }

.switch {
  appearance: none;
  width: 46px; height: 27px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  position: relative;
  flex: none;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform var(--t) var(--ease-spring), background var(--t) var(--ease);
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(19px); background: var(--text-on-accent); }

/* Selectable option card (onboarding, filters, quiz answers) */
.option {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  padding: 15px 18px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  transition: all var(--t) var(--ease);
}
.option:hover { border-color: var(--line-lit); background: var(--surface-2); transform: translateY(-1px); }
.option[aria-pressed="true"], .option.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.option.is-correct { border-color: var(--ok); background: rgba(62, 224, 160, 0.1); box-shadow: 0 0 0 1px var(--ok) inset; }
.option.is-wrong { border-color: var(--danger); background: rgba(255, 95, 87, 0.1); box-shadow: 0 0 0 1px var(--danger) inset; }
.option:disabled { cursor: default; }
.option-emoji { font-size: 20px; line-height: 1; flex: none; }
.option-key {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: var(--step--2);
  color: var(--text-3);
}

/* ======================================================================
   Avatar & rating
   ====================================================================== */

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-on-accent);
  background: linear-gradient(140deg, var(--accent), var(--accent-deep));
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
  user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: var(--step--2); }
.avatar-lg { width: 64px; height: 64px; font-size: var(--step-2); }
.avatar-xl { width: 96px; height: 96px; font-size: var(--step-4); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -10px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

.rating {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}
.rating .icon { width: 14px; height: 14px; color: var(--warn); }

/* ======================================================================
   States: skeleton, empty, error, offline
   ====================================================================== */

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-3) 37%, var(--surface) 63%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-text { height: 12px; border-radius: 99px; }
.skeleton-card { height: 150px; border-radius: var(--r-lg); }

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: clamp(36px, 7vw, 64px) var(--sp-5);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
}
.state-icon {
  display: grid;
  place-items: center;
  width: 54px; height: 54px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--text-3);
}
.state-icon .icon { width: 24px; height: 24px; }
.state h3 { font-size: var(--step-1); }
.state p { color: var(--text-3); font-size: var(--step--1); max-width: 42ch; }
.state-error .state-icon { color: var(--danger); border-color: rgba(255, 95, 87, 0.3); }

.offline-bar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px);
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-3);
  font-size: var(--step--1);
  color: var(--text-2);
}
.offline-bar .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }

/* ======================================================================
   Overlays: modal, sheet, toast
   ====================================================================== */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: rgba(4, 5, 7, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade var(--t) var(--ease) both;
}

.modal {
  width: min(520px, 100%);
  max-height: min(84vh, 760px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-3);
  animation: pop var(--t-slow) var(--ease-spring) both;
}
.modal-wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }

.toast-region {
  position: fixed;
  z-index: 200;
  right: var(--sp-4);
  bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-3);
  animation: rise var(--t) var(--ease-out) both;
  font-size: var(--step--1);
}
.toast .icon { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast-ok .icon { color: var(--ok); }
.toast-xp .icon { color: var(--accent); }
.toast-error .icon { color: var(--danger); }
.toast-title { font-weight: 600; color: var(--text); }
.toast-body { color: var(--text-3); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all var(--t) var(--ease); }

/* ======================================================================
   Tabs & segmented control
   ====================================================================== */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-3);
  font-weight: 600;
  font-size: var(--step--1);
  white-space: nowrap;
  transition: all var(--t) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }

.underline-tabs { display: flex; gap: var(--sp-5); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.underline-tabs::-webkit-scrollbar { display: none; }
.underline-tab {
  position: relative;
  padding: 12px 2px;
  border: 0;
  background: none;
  color: var(--text-3);
  font-weight: 600;
  font-size: var(--step--1);
  white-space: nowrap;
}
.underline-tab[aria-selected="true"] { color: var(--text); }
.underline-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

/* ======================================================================
   Misc
   ====================================================================== */

.icon { width: 20px; height: 20px; flex: none; stroke-width: 1.75; }

.divider-label {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  color: var(--text-3);
  font-size: var(--step--1);
}
.divider-label::before, .divider-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--step--2);
  color: var(--text-3);
}

.scroll-x {
  display: flex;
  gap: var(--sp-4);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x > * { scroll-snap-align: start; flex: none; }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
