/* ==========================================================================
   Dusl — design tokens and styles
   Ported from the React Native theme (app/theme/*.ts) of the Expo app.
   Note: the "neutral" ramp is green in this app; "primary" is red.
   ========================================================================== */

:root {
  /* Palette — verbatim from app/theme/colors.ts */
  --neutral-100: #ffffff;
  --neutral-200: #b6fdb6;
  --neutral-300: #68d568;
  --neutral-400: #38a138;
  --neutral-500: #00990a;
  --neutral-600: #00800b;
  --neutral-700: #00660a;
  --neutral-800: #005907;
  --neutral-900: #004206;

  --primary-100: #ecb6b6;
  --primary-500: #a12b2b;
  --primary-600: #931515;

  /* Semantic */
  --bg: #eceae8;
  --surface: var(--neutral-100);
  --text: var(--neutral-800);
  --text-dim: var(--neutral-600);
  --border: var(--neutral-400);
  --tint: var(--primary-500);
  --error: #c03403;
  --error-bg: #f2d6cd;

  /* Card states */
  --warn-bg: #fff9e6;
  --warn-border: #fab124;

  /* Spacing — verbatim from app/theme/spacing.ts */
  --space-xxxs: 2px;
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-card-lg: 0 2px 4px rgba(0, 0, 0, 0.1);

  --tabbar-height: 64px;
  --column-width: 640px;
}

/* ==========================================================================
   Reset / base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  /* Prevent the iOS rubber-band flash behind the fixed tab bar. */
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; }
input { font: inherit; }

.boot {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-dim);
}

/* ==========================================================================
   Layout — mobile-first column, centered on desktop
   ========================================================================== */

.app {
  max-width: var(--column-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  padding: var(--space-lg) var(--space-lg)
           calc(var(--tabbar-height) + var(--space-xl) + env(safe-area-inset-bottom, 0px));
}

/* ==========================================================================
   Start screen
   Roughly the original 57/43 split: mascot above, single action below.
   ========================================================================== */

.screen--start {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  /* No tab bar on this screen, so only the safe area needs clearing. */
  padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
  min-height: 100dvh;
}

.start__top {
  flex: 1 1 57%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  min-height: 0;
}

.start__heading {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  text-wrap: balance;
}

.start__image {
  display: block;
  max-width: 100%;
  /* Shrink to fit short viewports rather than pushing the button off-screen. */
  min-height: 0;
  max-height: 46vh;
  width: auto;
  height: auto;
  object-fit: contain;
  /* The artwork has an off-white backdrop, which would otherwise show as a
     hard square against the page background. */
  border-radius: var(--radius-xl);
}

.start__bottom {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  padding-top: var(--space-lg);
}

.start__bottom .btn {
  /* It is an <a>, so the button styles need the link bits neutralised. */
  text-decoration: none;
  font-size: 18px;
}

/* ==========================================================================
   Screen header
   ========================================================================== */

.screen-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.screen-header__title {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary-600);
  margin: 0 0 var(--space-xs);
  line-height: 1.2;
}

.screen-header__subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0;
}

/* ==========================================================================
   Cards / surfaces
   ========================================================================== */

.card {
  background: var(--surface);
  border: 2px solid var(--primary-600);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.card--shadow { box-shadow: var(--shadow-card-lg); }

.label {
  display: block;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.info-box {
  background: var(--neutral-200);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-top: var(--space-lg);
}

.info-box__text {
  margin: 0;
  font-size: 14px;
  color: var(--neutral-900);
  text-align: center;
}

/* ==========================================================================
   Inputs
   ========================================================================== */

.input {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  background: var(--surface);
  color: var(--neutral-900);
  /* 16px minimum stops iOS Safari from zooming on focus. */
  font-size: 16px;
}

.input:focus {
  outline: 2px solid var(--neutral-500);
  outline-offset: -1px;
}

.input::placeholder { color: #8aa88a; }

.field { margin-bottom: var(--space-md); }

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

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  width: 100%;
  min-height: 56px;
  padding: var(--space-sm);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--neutral-800);
  color: var(--neutral-100);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  /* Kill the 300ms tap delay and the grey flash on mobile. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { filter: brightness(0.9); }

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

/* Light-green variant. The RN original kept white label text here, which is
   only ~2:1 against #68d568; dark green keeps the same colour scheme and is
   readable. */
.btn--soft {
  background: var(--neutral-300);
  color: var(--neutral-900);
}

.btn--danger {
  background: var(--primary-600);
  color: var(--neutral-100);
}

.btn--outline {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--neutral-900);
}

.btn--sm {
  min-height: 40px;
  font-size: 14px;
  padding: var(--space-xs) var(--space-sm);
  width: auto;
}

/* ==========================================================================
   Tab bar
   ========================================================================== */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  max-width: var(--column-width);
  margin: 0 auto;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xxs);
  min-height: var(--tabbar-height);
  padding: var(--space-xs) var(--space-xxs);
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  line-height: 16px;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tab--active { color: var(--tint); }
.tab__icon { display: block; }

/* ==========================================================================
   States: loading / empty / error
   ========================================================================== */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xxl) var(--space-lg);
  text-align: center;
  color: var(--text-dim);
}

.state__text { margin: 0; }

.state--error .state__text { color: var(--error); }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--neutral-200);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  * { transition: none !important; }
}

.banner {
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: 14px;
}

/* ==========================================================================
   Learning screen
   ========================================================================== */

.prompt-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 110px;
  padding: var(--space-lg);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-lg);
  text-align: center;
}

.prompt-card__text {
  margin: 0;
  font-size: 30px;
  line-height: 35px;
  /* The completion card contains a literal newline. */
  white-space: pre-line;
}

.prompt-card--solution { margin-top: var(--space-lg); }

.learning__reveal { margin: var(--space-lg) 0; }

.result-buttons {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.result-buttons .btn { flex: 1; }

.settings {
  margin-top: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ==========================================================================
   Card list
   ========================================================================== */

.search { margin-bottom: var(--space-md); }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list__item { margin-bottom: var(--space-sm); }

.vocab {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  padding: var(--space-md);
  border: 2px solid var(--neutral-400);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  text-align: left;
}

/* The row itself is a container, so the speaker button can sit beside the
   tappable area rather than nested inside another button. */
.vocab__main {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* 0 correct in a row — needs practice */
.vocab--danger {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

/* mastered (> 4 correct in a row) */
.vocab--mastered {
  background: var(--neutral-200);
  border-color: var(--neutral-600);
}

.vocab__status {
  min-width: 24px;
  text-align: center;
  font-size: 16px;
}

.vocab__target,
.vocab__native {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  color: var(--neutral-900);
  overflow-wrap: anywhere;
}

.vocab__native { text-align: right; }

.vocab__arrow {
  font-size: 16px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.vocab-actions {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: var(--space-xs);
  background: var(--surface);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-lg);
  margin-top: var(--space-sm);
  padding: var(--space-sm);
}

.vocab-actions__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xxs);
  background: none;
  border: none;
  padding: var(--space-xs);
  cursor: pointer;
  color: var(--neutral-700);
  font-size: 10px;
  touch-action: manipulation;
}

.vocab-actions__icon { font-size: 24px; }

.vocab-edit {
  background: var(--surface);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-lg);
  margin-top: var(--space-sm);
  padding: var(--space-sm);
}

.vocab-edit__row {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.vocab-edit__row .btn { flex: 1; }

.list-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-md);
}

/* ==========================================================================
   Card input
   ========================================================================== */

.hint {
  margin: var(--space-md) 0 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.toast {
  background: var(--neutral-200);
  color: var(--neutral-900);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: 14px;
  text-align: center;
}

/* ==========================================================================
   Pronunciation (Forvo)
   ========================================================================== */

.speak {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  /* Comfortable tap target without bloating the list row. */
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--neutral-700);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.speak:hover { background: rgba(0, 128, 11, 0.1); }
.speak:active { background: rgba(0, 128, 11, 0.18); }

.speak--playing { color: var(--primary-600); }

.speak--missing,
.speak--disabled {
  color: var(--neutral-400);
  opacity: 0.55;
  cursor: default;
}

.speak--error { color: var(--error); }

.speak__icon { display: block; }

.speak__spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--neutral-200);
  border-top-color: var(--neutral-700);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Visually hidden but available to screen readers. */
.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;
}
