:root {
  color-scheme: dark light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #2f6fed;
  --border: #e2e2e6;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012;
    --surface: #1c1c1e;
    --text: #f2f2f3;
    --muted: #9a9a9f;
    --accent: #5b8dfd;
    --border: #2c2c2e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.topbar nav a {
  margin-left: 16px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95em;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

h1 { font-size: 1.4em; margin: 0 0 12px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hint { color: var(--muted); font-size: 0.9em; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn {
  display: inline-block;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  text-decoration: none;
  font-size: 0.95em;
  cursor: pointer;
  text-align: center;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-subtle {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  font-size: 0.9em;
  cursor: pointer;
  text-decoration: underline;
}

.delete-form {
  margin-top: 24px;
}

.link-btn.danger {
  color: #d64545;
}

/* Card list */

.card-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.card-list-question :is(p, ul, ol) { margin: 0; }

.card-list-meta {
  margin-top: 8px;
  display: flex;
  gap: 14px;
}

.card-list-meta a {
  color: var(--accent);
  font-size: 0.9em;
  text-decoration: none;
}

/* Card form */

.card-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
}

.card-form label {
  font-weight: 600;
  font-size: 0.9em;
  margin-top: 10px;
}

.card-form textarea,
.card-form input[type="password"],
.card-form input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1em;
}

.card-form textarea {
  resize: vertical;
}

.error {
  color: #d64545;
  font-size: 0.9em;
}

/* Review / flip card */

.progress {
  color: var(--muted);
  font-size: 0.9em;
  margin-bottom: 10px;
}

.flip-card {
  perspective: 1200px;
  cursor: pointer;
}

/* Both faces sit in the same grid cell so the card's height auto-fits
   the taller of the two sides, instead of a fixed height that overflows
   with long content (e.g. a 10-item list). */
.flip-card-inner {
  position: relative;
  display: grid;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-face {
  position: relative;
  grid-area: 1 / 1;
  min-height: 220px;
  max-height: 75vh;
  overflow-y: auto;
  backface-visibility: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.flip-card-back {
  transform: rotateY(180deg);
}

.card-content {
  font-size: 1.15em;
}

.card-content :is(p, ul, ol) { margin: 0.4em 0; }

/* Lists tend to be longer (e.g. enumerations) — left-align and shrink
   slightly so ~10 items fit comfortably instead of forcing a scrollbar. */
.card-content:has(ul, ol) {
  text-align: left;
  font-size: 1em;
}

.card-content:has(ul, ol) :is(ul, ol) {
  margin: 0;
  padding-left: 1.3em;
}

.card-content:has(ul, ol) li {
  margin: 0.15em 0;
}

.tap-hint {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.75em;
}

.review-actions {
  margin-top: 20px;
}
