:root {
  --bg: #0f1419;
  --surface: #1a212b;
  --surface-2: #232c38;
  --border: #313c4a;
  --text: #e7ecf2;
  --muted: #93a1b1;
  --accent: #4f9cff;
  --accent-2: #2d6fd6;
  --danger: #e5534b;
  --front: #2b3a55;
  --back: #2f4a3a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Always reserve room for the vertical scrollbar so expanding the word deck
   (which makes the page taller) doesn't shift the layout sideways. */
html {
  scrollbar-gutter: stable;
  overflow-y: scroll; /* fallback for browsers without scrollbar-gutter */
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #18222f, var(--bg));
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.app__header { text-align: center; margin-bottom: 24px; }
.app__header h1 { margin: 0; font-size: 1.9rem; letter-spacing: -0.5px; }
.app__subtitle { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }

/* Gate (profile selection screen) */
.gate {
  max-width: 460px;
  margin: 0 auto;
  padding: 48px 20px 64px;
}
.gate__panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 12px;
}
.tiles { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tile {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile__name { flex: 1; font-weight: 600; }
.tile__lock { color: var(--muted); font-size: 0.95rem; }
.tiles .empty { background: transparent; border: none; padding: 4px 2px; }
.gate__new { width: 100%; }
.gate__form { display: flex; flex-direction: column; gap: 12px; }
.gate__input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 1.05rem;
}
.gate__input:focus { outline: none; border-color: var(--accent); }
.gate__actions { display: flex; gap: 10px; }
.gate__actions .ctrl-btn { flex: 1; }

/* App header bar */
.app__header--bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
}
.app__header--bar h1 { font-size: 1.4rem; }
.app__header--bar .app__subtitle { margin-top: 2px; }
.app__headerActions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* Modes */
.modes {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.mode-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.mode-btn:hover { color: var(--text); border-color: var(--accent); }
.mode-btn.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* Card */
.stage { margin-bottom: 36px; }
.stage__row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 16px;
}
.nav-btn {
  flex: 0 0 64px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 2.6rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-btn:hover { color: #fff; border-color: var(--accent); background: var(--surface-2); }
.nav-btn:active { transform: translateY(1px); }
.card {
  perspective: 1400px;
  flex: 1 1 auto;
  min-width: 0;
  height: 260px;
  cursor: pointer;
}
.card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.card.is-flipped .card__inner { transform: rotateY(180deg); }
.card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.card__face--front { background: linear-gradient(160deg, var(--front), var(--surface-2)); }
.card__face--back {
  background: linear-gradient(160deg, var(--back), var(--surface-2));
  transform: rotateY(180deg);
}
.card__lang {
  position: absolute;
  top: 16px;
  left: 18px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}
.card__word {
  font-size: 2.1rem;
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 10px;
}
.controls--secondary { margin-bottom: 0; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 70px; text-align: center; }

.ctrl-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ctrl-btn:hover { border-color: var(--accent); }
.ctrl-btn:active { transform: translateY(1px); }
.ctrl-btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.ctrl-btn--primary:hover { background: var(--accent-2); }
.ctrl-btn--ghost { background: transparent; }
.ctrl-btn--danger { background: transparent; color: var(--danger); border-color: transparent; }
.ctrl-btn--danger:hover { border-color: var(--danger); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel__title { margin: 0 0 16px; font-size: 1.05rem; }

/* Collapsible "Your words" header */
.panel__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.panel__toggle .panel__title { margin: 0; }
.panel__toggle .chev { color: var(--muted); font-size: 0.9rem; transition: transform 0.15s ease; }
.panel__toggle[aria-expanded="true"] .panel__title { margin-bottom: 0; }

.search {
  width: 100%;
  margin: 16px 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}
.search:focus { outline: none; border-color: var(--accent); }

/* Inline edit inputs in the word list */
.w-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.w-input:focus { outline: none; }
.w-edit, .w-save {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.w-edit:hover { color: var(--accent); background: var(--surface-2); }
.w-save { color: var(--accent); }
.w-save:hover { background: var(--surface-2); }

.add-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.78rem; color: var(--muted); }
.field input {
  width: 100%;
  min-width: 0; /* let the input shrink inside its grid track instead of overflowing */
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--accent); }

.import-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.file-label {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.file-label:hover { border-color: var(--accent); }
.link { color: var(--accent); font-size: 0.88rem; text-decoration: none; }
.link:hover { text-decoration: underline; }

.hint { color: var(--muted); font-size: 0.82rem; margin: 6px 0 0; }
.hint code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
}
.status { font-size: 0.85rem; margin: 8px 0 0; min-height: 1.2em; color: var(--accent); }

/* Word list */
.word-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.word-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
}
.word-list li:nth-child(odd) { background: var(--bg); }
.word-list .w-en { flex: 1; }
.word-list .w-cz { flex: 1; color: var(--muted); }
.word-list .w-del {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.word-list .w-del:hover { color: var(--danger); background: var(--surface-2); }
.empty { color: var(--muted); font-size: 0.9rem; padding: 8px 12px; }

@media (max-width: 520px) {
  /* Stack the add-word fields vertically so they never overflow a phone. */
  .add-form { grid-template-columns: 1fr; }
  .add-form .ctrl-btn--primary { grid-column: 1 / -1; }
  .card__word { font-size: 1.7rem; }
  .nav-btn { flex-basis: 46px; font-size: 2rem; }
  .stage__row { gap: 8px; }
}
