:root {
  --bg: #f6f7fb; --surface: #fff; --text: #1d2130; --muted: #6b7185; --line: #e2e5ee;
  --accent: #3b5bdb; --accent-text: #fff; --danger: #c92a2a; --ok: #2b8a3e; --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b; --surface: #1c1f2a; --text: #e8eaf2; --muted: #9298ad; --line: #2c3040;
    --accent: #748ffc; --accent-text: #0d1020; --danger: #ff8787; --ok: #69db7c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2em 0 .3em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.logout { display: flex; gap: 10px; align-items: center; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.error { color: var(--danger); font-weight: 500; }
.ok { color: var(--ok); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 20px; }
.center .actions, .actions.center { justify-content: center; }
.crumb { margin: 0 0 4px; font-size: .95rem; }
.crumb a { text-decoration: none; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin: 16px 0;
}
.narrow { max-width: 420px; margin: 32px auto; }

label { display: block; font-weight: 500; margin: 0 0 14px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
.inline input { width: auto; margin: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn.big { min-height: 52px; padding: 12px 28px; font-size: 1.05rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

.sets { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.sets a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: var(--text);
}
.sets .t { font-weight: 600; overflow-wrap: anywhere; }
.sets .n { color: var(--muted); font-size: .9rem; white-space: nowrap; }

.rename summary { list-style: none; display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.rename summary::-webkit-details-marker { display: none; }
.rename form { margin: 8px 0; }
.rename input { flex: 1; min-width: 0; margin: 0; }

.cards { padding: 0; list-style: none; margin: 16px 0; display: grid; gap: 8px; }
.cards li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.pair { display: grid; grid-template-columns: 1fr 1.6fr; gap: 14px; }
.term { font-weight: 600; }
.term, .def { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 560px) { .pair { grid-template-columns: 1fr; gap: 4px; } }
.edit summary { color: var(--accent); cursor: pointer; font-size: .88rem; margin-top: 6px; width: fit-content; }
.edit form { margin-top: 10px; }
.add textarea { min-height: 44px; }
.danger-zone { margin: 32px 0 16px; text-align: center; }

/* Bulk tools stay on the desktop site, not the installed app. */
@media (display-mode: standalone) { .desktop-tool { display: none !important; } }
@media (hover: none) { .desktop-tool { display: none; } }
@media (hover: hover) { .phone-hint { display: none; } }

/* Import */
.howto { margin: 0 0 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.howto summary { cursor: pointer; font-weight: 500; }
.import textarea#text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; tab-size: 4; }
.seps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .seps { grid-template-columns: 1fr; } }
.preview { margin: 8px 0 20px; }
.problems p { margin: 4px 0; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 12%, transparent); font-size: .9rem; overflow-wrap: anywhere; }
.cards.compact li { padding: 8px 12px; font-size: .95rem; }
.cards.compact .ln { color: var(--muted); font-size: .8rem; }
.joined { color: var(--muted); font-size: .8rem; }

/* Study */
.study-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.study-top a { text-decoration: none; overflow-wrap: anywhere; }
.stage { perspective: 1400px; margin: 16px 0; }
.flash {
  display: block; width: 100%; min-height: min(56vh, 420px); padding: 0; border: 0;
  cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.flash .inner {
  position: relative; display: block; width: 100%; min-height: inherit;
  transition: transform .45s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d;
}
.flash.flipped .inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,.07); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: auto;
}
.face.back { transform: rotateY(180deg); }
.face .label { position: absolute; top: 12px; left: 16px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.face .text { font-size: clamp(1.2rem, 4.5vw, 1.9rem); line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; text-align: center; max-width: 100%; }
.face .text.long { font-size: 1.05rem; text-align: left; }
@media (prefers-reduced-motion: reduce) { .flash .inner { transition: none; } }
.controls { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 10px; }
.controls .btn { min-height: 52px; font-size: 1.1rem; }

/* Match */
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.1rem; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
@media (max-width: 560px) { .board { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
.tile {
  min-height: 96px; padding: 10px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: .98rem; line-height: 1.3;
  overflow-wrap: anywhere; cursor: pointer; -webkit-tap-highlight-color: transparent;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 7; overflow: hidden;
  transition: opacity .2s, transform .2s, border-color .15s, background .15s;
}
.tile.t { font-weight: 600; }
.tile.long { font-size: .82rem; }
.tile.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.tile.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 18%, var(--surface)); }
.tile.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, var(--surface)); animation: shake .35s; }
.tile.gone { opacity: 0; transform: scale(.9); pointer-events: none; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .tile.wrong { animation: none; } }
