/* Lambdaorbit Flashcards — mobile-first CSS.
   No frameworks, no build step. */

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #818cf8;
  --accent-2: #4f46e5;
  --known: #22c55e;
  --learning: #f59e0b;
  --danger: #ef4444;
  --tier-1: #38bdf8;   /* C1/C2 boundary */
  --tier-2: #a855f7;   /* proper C2      */
  --tier-3: #ef4444;   /* GRE-hard       */
  --radius: 18px;
  --shadow: 0 8px 24px -8px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Standalone mode (installed as home-screen app on iOS/Android): reserve
   room for the notch / bottom bar so the header + footer aren't clipped. */
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============ Gate page ============ */
body.gate {
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}
.gate-panel {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  padding: 32px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-panel h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: .3px; }
.gate-panel .subtle { margin: 0 0 24px; color: var(--muted); }
.gate-panel input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--panel-2);
  background: #0b1220;
  color: var(--text);
  font-size: 16px;   /* >= 16px to avoid iOS zoom */
  margin-bottom: 12px;
}
.gate-panel button {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 0;
  background: var(--accent-2);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.gate-panel button:hover { background: var(--accent); }
.gate-panel .err {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
}

/* ============ App layout ============ */
header {
  padding: 12px 16px calc(12px + env(safe-area-inset-top)) 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.lang-toggle {
  display: inline-flex;
  background: var(--panel);
  border-radius: 999px;
  padding: 4px;
}
.lang-toggle button {
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
}
.lang-toggle button[aria-selected="true"] {
  background: var(--accent-2);
  color: white;
}
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.linky {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
}
.linky:hover { color: var(--text); }

main#stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  perspective: 1200px;
}
.empty {
  color: var(--muted);
  text-align: center;
}

/* ============ Card ============ */
.card {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 3 / 4;
  max-height: min(72vh, 640px);
  position: relative;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card.flipped { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  backface-visibility: hidden;
  overflow: hidden;
}
.face.back { transform: rotateY(180deg); align-items: stretch; justify-content: flex-start; text-align: left; }

/* Front */
.front .word {
  font-size: clamp(36px, 8vw, 64px);
  font-weight: 700;
  letter-spacing: .5px;
  line-height: 1.1;
  word-break: break-word;
}
.front .hint {
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.front .pos {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

/* Tier stripe */
.card.tier-1 .face::before,
.card.tier-2 .face::before,
.card.tier-3 .face::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
}
.card.tier-1 .face::before { background: var(--tier-1); }
.card.tier-2 .face::before { background: var(--tier-2); }
.card.tier-3 .face::before { background: var(--tier-3); }

/* Back */
.back .row {
  margin-bottom: 14px;
}
.back .row:last-child { margin-bottom: 0; }

.back .label {
  display: block;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.back .headline {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
}
.back .ipa {
  color: var(--muted);
  font-size: 15px;
  margin-top: 6px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.back .definition {
  font-size: 18px;
  line-height: 1.4;
}
.back .example {
  font-size: 16px;
  line-height: 1.45;
  color: #e2e8f0;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  font-style: italic;
}
.back .example-en {
  color: var(--muted);
  font-style: normal;
  border-left-color: var(--panel-2);
  font-size: 14px;
}
.back .article {
  color: var(--accent);
  font-weight: 700;
  margin-right: 6px;
}

/* End-of-deck */
.finished {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}
.finished h2 { color: var(--text); margin-top: 0; }
.finished button {
  margin-top: 10px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 0;
  background: var(--accent-2);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

/* ============ Footer actions ============ */
footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-top: 1px solid rgba(255,255,255,.06);
}
.action {
  flex: 1;
  padding: 14px 16px;
  border: 0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: white;
}
.action.learning { background: var(--learning); color: #1a1305; }
.action.known    { background: var(--known);    color: #052e13; }
.action:active { transform: translateY(1px); }
.logout-form { margin-left: auto; margin-top: 0; }

/* Tablet/desktop tweaks */
@media (min-width: 720px) {
  header { padding: 16px 24px; }
  footer { padding: 16px 24px; }
  main#stage { padding: 24px; }
  .face { padding: 40px 36px; }
}
