/* ==================================================================
   COMPONENTS — DUOLINGO DESIGN SYSTEM KIT

   Tactile 3D buttons, bouncy cards, playful gamified pills,
   chunky progress meters, high-contrast dialogue bubbles.
================================================================== */

/* ------------------------------------------------------- shell --- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: var(--app-width);
  margin-inline: auto;
  background: var(--bg);
  animation: screen-in var(--dur-2) var(--ease-out);
}

@media (min-width: 600px) {
  .screen {
    border-inline: 2px solid var(--line);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.05);
  }
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen__scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--gutter) 0;
  -webkit-overflow-scrolling: touch;
}

/* ------------------------------------------------------- appbar --- */
.appbar {
  position: relative;
  z-index: var(--z-appbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: max(var(--space-3), calc(var(--safe-top) + var(--space-2))) var(--space-4) var(--space-3);
  border-bottom: 2px solid var(--line);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.appbar__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  font-size: var(--size-lead);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}

.appbar__slot {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.appbar__progress { flex: 1; }

.appbar__count {
  margin-top: var(--space-1);
  text-align: center;
  font-size: var(--size-caption);
  font-weight: var(--weight-semibold);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* Top Stat Badge Pills (Streak, Reviews, etc.) */
.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--line);
  background: var(--bg);
  font-size: var(--size-small);
  font-weight: var(--weight-bold);
  color: var(--text);
  box-shadow: 0 2px 0 var(--line);
  transition: transform var(--dur-1) var(--ease-out);
}

.stat-pill:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 transparent;
}

.stat-pill--streak {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, var(--line));
}

.stat-pill--due {
  color: var(--brand-blue);
  border-color: color-mix(in srgb, var(--brand-blue) 40%, var(--line));
}

.stat-pill__icon {
  font-size: 16px;
  line-height: 1;
}

/* ------------------------------------------------------ buttons --- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: var(--space-3) var(--space-5);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: var(--size-body);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  text-decoration: none;
  background: var(--bg);
  color: var(--brand-blue);
  border-color: var(--line);
  box-shadow: 0 4px 0 var(--line);
  cursor: pointer;
  user-select: none;
  transition: transform var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out), background-color var(--dur-1);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--line);
}

.btn--primary {
  background: var(--brand);
  color: var(--on-brand);
  border-color: transparent;
  box-shadow: 0 4px 0 var(--brand-shade);
}

.btn--primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brand-shade);
}

.btn--secondary {
  background: var(--brand-blue);
  color: var(--on-brand);
  border-color: transparent;
  box-shadow: 0 4px 0 var(--brand-blue-shade);
}

.btn--secondary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brand-blue-shade);
}

.btn--danger {
  background: var(--danger);
  color: var(--on-brand);
  border-color: transparent;
  box-shadow: 0 4px 0 var(--danger-shade);
}

.btn--danger:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--danger-shade);
}

.btn--lg {
  min-height: 54px;
  font-size: var(--size-lead);
  border-radius: var(--radius-lg);
}

.btn--block { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  box-shadow: 0 4px 0 var(--line);
}

.btn--primary:disabled {
  background: var(--line-2);
  box-shadow: 0 4px 0 var(--line-3);
}

/* Destructive action that should not shout. */
.btn--ghost-danger {
  margin-top: var(--space-3);
  color: var(--danger);
  border-color: transparent;
  box-shadow: none;
  background: none;
}

.btn--ghost-danger:active { transform: none; box-shadow: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text-muted);
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
  transition: all var(--dur-1) var(--ease-out);
}

.icon-btn:hover { color: var(--text); }
.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--line);
}
.icon-btn svg { width: 20px; height: 20px; display: block; }

.icon-btn--brand {
  background: var(--brand-blue);
  border-color: transparent;
  color: var(--on-brand);
  box-shadow: 0 3px 0 var(--brand-blue-shade);
}

.icon-btn--brand:hover { color: var(--on-brand); }
.icon-btn--brand:active { box-shadow: 0 1px 0 var(--brand-blue-shade); }

.icon-btn--sm {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}

.icon-btn--sm svg { width: 16px; height: 16px; }

/* ------------------------------------------------------- panel --- */
.panel {
  margin-bottom: var(--space-5);
}

.panel--framed {
  padding: var(--space-4);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow-card);
}

.panel--inset {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--bg-sunken);
  border: 2px solid var(--line);
}

.panel--gear {
  padding-left: var(--space-4);
  border-left: 4px solid var(--gear);
}

/* --------------------------------------------------------- list ---
   Duolingo Card Tiles */
.list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.list__item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-4);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: inherit;
  text-align: left;
  box-shadow: var(--shadow-card);
  transition: transform var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out), border-color var(--dur-1);
}

.list__item--muted {
  opacity: 0.55;
  background: var(--bg-sunken);
}

button.list__item {
  cursor: pointer;
}

button.list__item:active {
  transform: translateY(3px);
  box-shadow: var(--shadow-card-active);
}

.list__body {
  flex: 1;
  min-width: 0;
}

.list__emoji {
  flex: 0 0 auto;
  font-size: 28px;
  line-height: 1;
}

.list__item--feature {
  border-color: color-mix(in srgb, var(--brand-blue) 45%, var(--line));
  background: var(--wash-brand);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--brand-blue) 45%, var(--line));
}

button.list__item--feature:active {
  box-shadow: 0 1px 0 color-mix(in srgb, var(--brand-blue) 45%, var(--line));
}

.list__title {
  display: block;
  font-size: var(--size-lead);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}

.list__sub {
  display: block;
  margin-top: 2px;
  font-size: var(--size-small);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
}

.list__meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--size-caption);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  border: 2px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.list__meta--active {
  background: var(--wash-brand);
  border-color: var(--brand-blue);
  color: var(--brand-blue);
}

.list__meta--done {
  background: var(--wash-success);
  border-color: var(--success);
  color: var(--success);
}

button.list__body {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* ---------------------------------------------------------- dot --- */
.dot {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  background: var(--gear);
  box-shadow: 0 2px 0 var(--gear-shade);
  flex-shrink: 0;
}

.gear-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--wash-gear);
  border: 2px solid color-mix(in srgb, var(--gear) 40%, transparent);
}

.gear-label__text {
  font-size: var(--size-caption);
  font-weight: var(--weight-bold);
  color: var(--gear);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.gear-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--gear);
  color: #ffffff;
  font-size: var(--size-caption);
  font-weight: var(--weight-bold);
  box-shadow: 0 3px 0 var(--gear-shade);
}

/* -------------------------------------------------------- meter ---
   Duolingo Thick Capsule Progress Bar with Gloss Highlight */
.meter {
  position: relative;
  height: 14px;
  border-radius: var(--radius-pill);
  background: var(--line);
  overflow: hidden;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.08);
}

.meter__fill {
  position: relative;
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--brand);
  transition: width var(--dur-3) var(--ease-out);
}

.meter__fill::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 6px;
  right: 6px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.4);
}

.meter--thin { height: 8px; }
.meter__fill--gear { background: var(--gear); }
.meter__fill--brand { background: var(--brand); }

/* ------------------------------------------------------- metric --- */
.metric__value {
  display: block;
  font-size: var(--size-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}

.metric__label {
  display: block;
  margin-top: 2px;
  font-size: var(--size-caption);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ---------------------------------------------------------- row --- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  box-shadow: var(--shadow-card);
  margin-bottom: var(--space-3);
}

.row { flex-wrap: wrap; }
.row__body { flex: 1 1 170px; min-width: 0; }

.row__title {
  font-size: var(--size-body);
  font-weight: var(--weight-bold);
}

.row__sub {
  margin-top: 2px;
  font-size: var(--size-small);
  color: var(--text-muted);
}

/* ------------------------------------------------------- switch --- */
.switch {
  position: relative;
  width: 50px;
  height: 30px;
  flex: 0 0 50px;
}

.switch__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.switch__track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--line-2);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background-color var(--dur-2);
}

.switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: #ffffff;
  box-shadow: 0 3px 0 var(--line-2);
  transition: transform var(--dur-2) var(--ease-pop);
}

.switch__input:checked + .switch__track {
  background: var(--brand);
}

.switch__input:checked + .switch__track::after {
  transform: translateX(20px);
  box-shadow: 0 3px 0 var(--brand-shade);
}

/* ------------------------------------------------------ segment --- */
.segment {
  display: inline-flex;
  padding: 4px;
  border-radius: var(--radius-lg);
  background: var(--bg-inset);
  border: 2px solid var(--line);
}

.segment__btn {
  min-height: 36px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-muted);
  font-size: var(--size-small);
  font-weight: var(--weight-bold);
  cursor: pointer;
  transition: all var(--dur-1);
}

.segment__btn[aria-pressed='true'] {
  background: var(--bg);
  color: var(--brand-blue);
  box-shadow: 0 2px 0 var(--line);
}

/* -------------------------------------------------------- field --- */
.field__control {
  min-height: 42px;
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: max(16px, var(--size-small)); /* < 16px makes iOS zoom on focus */
  font-weight: var(--weight-bold);
  text-align: center;
  box-shadow: 0 2px 0 var(--line);
}

.field__control--number { width: 80px; }
.field__control--select { max-width: 190px; text-align: left; }
.field__control--text,
.field__control--search {
  width: 100%;
  min-height: var(--control-height);
  font-size: max(16px, var(--size-body));
  font-weight: var(--weight-medium);
  text-align: left;
}

.field__control--text:focus,
.field__control--search:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 2px 0 var(--brand-blue);
}

.field__control--search { -webkit-appearance: none; appearance: none; }

.field__control--range { width: 140px; border: 0; box-shadow: none; accent-color: var(--brand); }

/* ------------------------------------------------------- bubble ---
   Duolingo Chat Bubbles */
.bubble {
  position: relative;
  max-width: 86%;
  margin-bottom: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-bubble);
  font-size: var(--size-lead);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  border: 2px solid var(--line);
  box-shadow: var(--shadow-card);
}

.bubble--in {
  background: var(--bg);
  border-bottom-left-radius: 4px;
}

.bubble--out {
  margin-left: auto;
  background: var(--wash-brand);
  border-color: color-mix(in srgb, var(--brand-blue) 60%, var(--line));
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.bubble__translation {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--size-caption);
  font-weight: var(--weight-regular);
  color: var(--text-muted);
}

.blank {
  display: inline-block;
  min-width: 84px;
  padding: 2px 8px;
  border-bottom: 3px dashed var(--brand-blue);
  color: var(--brand-blue);
  font-weight: var(--weight-bold);
  text-align: center;
}

.blank--filled {
  border-bottom-style: solid;
  animation: pop var(--dur-2) var(--ease-pop);
}

@keyframes pop {
  0% { transform: scale(0.92); opacity: 0; }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}

/* -------------------------------------------------------- chips ---
   Horizontally scrolling filter pills — thumb-friendly on phones. */
.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--space-1);
  margin-inline: calc(-1 * var(--gutter));
  padding-inline: var(--gutter);
  scroll-padding-inline: var(--gutter);
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 var(--space-4);
  border: 2px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-muted);
  font-size: var(--size-small);
  font-weight: var(--weight-bold);
  white-space: nowrap;
  box-shadow: 0 2px 0 var(--line);
  cursor: pointer;
}

.chip:active { transform: translateY(2px); box-shadow: none; }

.chip[aria-pressed='true'] {
  background: var(--wash-brand);
  border-color: var(--brand-blue);
  color: var(--brand-blue);
  box-shadow: 0 2px 0 var(--brand-blue);
}

/* ---------------------------------------------------------- tag --- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--bg-inset);
  color: var(--text-muted);
}

.tag--casual { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning-shade); }
.tag--polite { background: var(--wash-brand); color: var(--brand-blue-shade); }

[data-theme='dark'] .tag--casual { color: var(--warning); }
[data-theme='dark'] .tag--polite { color: var(--brand-blue); }

/* -------------------------------------------------------- empty --- */
.empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

.empty__title {
  font-size: var(--size-lead);
  font-weight: var(--weight-bold);
}

.empty__sub {
  margin: var(--space-2) 0 var(--space-5);
  color: var(--text-muted);
}

/* --------------------------------------------------- action bar ---
   Sticky primary action at the bottom of a screen, in thumb reach. */
.action-bar {
  padding: var(--space-3) var(--gutter) calc(var(--space-3) + var(--safe-bottom));
  border-top: 2px solid var(--line);
  background: var(--bg);
}

/* -------------------------------------------------------- toast --- */
.toast {
  position: fixed;
  left: 50%;
  /* clears the grade bar and the sticky action bar */
  bottom: calc(var(--space-10) + var(--space-5) + var(--safe-bottom));
  width: max-content;
  max-width: calc(100vw - var(--space-7));
  text-align: center;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--ink-900);
  color: var(--text-inverse);
  font-size: var(--size-small);
  font-weight: var(--weight-bold);
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--dur-2) var(--ease-out);
}

@keyframes toast-in {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ------------------------------------------------------- dialog --- */
.dialog {
  width: min(380px, calc(100vw - var(--space-6)));
  padding: var(--space-6);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}

.dialog::backdrop {
  background: color-mix(in srgb, var(--ink-900) 45%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.dialog__title {
  font-size: var(--size-title);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-2);
}

.dialog__body {
  margin-bottom: var(--space-6);
  font-size: var(--size-body);
  color: var(--text-muted);
}

.dialog--sheet {
  padding: 0;
  max-height: calc(100dvh - var(--space-6));
  overflow-y: auto;
}

/* On phones the form rises from the bottom like a native sheet. */
@media (max-width: 599px) {
  .dialog--sheet {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    animation: sheet-in var(--dur-3) var(--ease-out);
  }
}

@keyframes sheet-in {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.dialog__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* ------------------------------------------------------ section --- */
.section {
  margin-bottom: var(--space-7);
}

.section__title {
  font-size: var(--size-title);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}

.section__sub {
  margin-top: var(--space-1);
  margin-bottom: var(--space-3);
  font-size: var(--size-small);
  color: var(--text-muted);
}
