:root {
  --bg: #fff8ef;
  --card: #ffffff;
  --ink: #2b2340;
  --muted: #6b6480;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --sky: #4aa8ff;
  --drop-bg: #f2f8ff;
  --drop-over: #e1efff;
  --chosen-bg: #fff1ec;
  --line: #f0e4d4;
  --error: #c62828;
  --shadow: 0 6px 24px rgba(43, 35, 64, 0.08);
  color-scheme: light;
}

/* Dark tokens: used when the device prefers dark and the visitor hasn't picked light,
   or when the visitor picked dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1726;
    --card: #262036;
    --ink: #f3eefc;
    --muted: #b3abc6;
    --accent: #ff7a5c;
    --accent-ink: #1b1726;
    --sky: #6cb8ff;
    --drop-bg: #1f2a3a;
    --drop-over: #263650;
    --chosen-bg: #3a2730;
    --line: #3a3350;
    --error: #ff8a80;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1b1726;
  --card: #262036;
  --ink: #f3eefc;
  --muted: #b3abc6;
  --accent: #ff7a5c;
  --accent-ink: #1b1726;
  --sky: #6cb8ff;
  --drop-bg: #1f2a3a;
  --drop-over: #263650;
  --chosen-bg: #3a2730;
  --line: #3a3350;
  --error: #ff8a80;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  line-height: 1.5;
}

.top { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.settings { display: flex; align-items: center; gap: 10px; }
.langs { display: flex; gap: 4px; background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.langs a { color: var(--muted); text-decoration: none; font-weight: 700; font-size: 0.85rem; padding: 6px 10px; border-radius: 999px; }
.langs a[aria-current] { background: var(--accent); color: var(--accent-ink); }
.langs a:focus-visible, .theme:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.theme { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); cursor: pointer; font-size: 1.1rem; }
.theme .sun { display: none; }
:root[data-theme="dark"] .theme .moon { display: none; }
:root[data-theme="dark"] .theme .sun { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .moon { display: none; }
  :root:not([data-theme="light"]) .theme .sun { display: inline; }
}
.brand { font-family: "Baloo 2", sans-serif; font-weight: 700; font-size: 1.5rem; }
.logo { margin-right: 4px; }

main { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }

.hero { text-align: center; margin: 16px 0 28px; }
.hero h1 { font-family: "Baloo 2", sans-serif; font-size: clamp(1.8rem, 5vw, 2.6rem); line-height: 1.15; margin: 0 0 12px; }
.hero p { color: var(--muted); margin: 0; font-size: 1.1rem; }

.card {
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

/* Elements we hide from script must stay hidden even when their class sets a display. */
[hidden] { display: none !important; }

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 200px;
  border: 3px dashed var(--sky);
  border-radius: 18px;
  background: var(--drop-bg);
  text-align: center;
  padding: 20px;
  cursor: pointer;
  color: var(--muted);
}
.drop.over { background: var(--drop-over); }
.drop strong { color: var(--ink); font-size: 1.1rem; }
.drop img { max-height: 220px; max-width: 100%; border-radius: 12px; }

/* Take a photo with the camera, as an alternative to choosing one */
.camera-row { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 12px; }
.camera-row .or { color: var(--muted); font-weight: 700; }
.camera-row .secondary { width: 100%; }
.camera video {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  border-radius: 18px;
  background: #000000;
}
/* Like a mirror for selfies; the captured photo itself is not flipped. */
.camera video.mirror { transform: scaleX(-1); }

.detail { border: 0; padding: 0; margin: 20px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.detail legend { font-weight: 700; margin-bottom: 8px; }
.detail label span {
  display: block;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 6px;
  font-weight: 700;
  cursor: pointer;
}
.detail small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.detail input { position: absolute; opacity: 0; }
.detail input:checked + span { border-color: var(--accent); background: var(--chosen-bg); }
.detail input:focus-visible + span { outline: 3px solid var(--sky); }

.primary, .secondary {
  display: inline-block;
  font: 700 1.1rem "Nunito", sans-serif;
  border-radius: 999px;
  padding: 14px 28px;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.secondary { background: transparent; color: var(--ink); border: 2px solid var(--ink); }

.error { color: var(--error); font-weight: 700; margin: 12px 0 0; }

.result { text-align: center; }
.result h2 { font-family: "Baloo 2", sans-serif; margin-top: 0; }
/* The drawing is a sheet of paper, so it stays white in dark mode too. */
.result img { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #ffffff; }
.actions { display: flex; gap: 12px; margin-top: 16px; }
.actions > * { flex: 1; }

.privacy { text-align: center; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 480px) {
  .detail { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
}

/* Header account link */
.brand { color: var(--ink); text-decoration: none; }
.pill { color: var(--ink); background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-weight: 700; padding: 9px 16px; border-radius: 999px; }
.pill.accent { background: var(--accent); color: var(--accent-ink); }
.pill:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* Free drawings left / sign-in prompt above the upload card */
.quota, .notice { text-align: center; margin: -8px 0 16px; color: var(--muted); font-weight: 700; }
.quota a, .notice a, .error a, .links a { color: var(--accent); }

/* Login and account pages */
.narrow { max-width: 460px; margin: 8px auto 24px; }
.narrow h1 { font-family: "Baloo 2", sans-serif; font-size: 1.8rem; line-height: 1.2; margin: 0 0 8px; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.stack label { font-weight: 700; }
.stack input {
  font: 400 1.1rem "Nunito", sans-serif;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.stack input:focus { outline: 3px solid var(--sky); outline-offset: 1px; border-color: transparent; }
.stack input.code { font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; }
.links { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: 700 1rem "Nunito", sans-serif; cursor: pointer; text-decoration: underline; }
.plan { display: flex; flex-direction: column; gap: 2px; background: var(--chosen-bg); border-radius: 14px; padding: 14px 16px; margin: 16px 0; }
.plan span { color: var(--muted); }
.note { background: var(--drop-bg); border-radius: 14px; padding: 12px 14px; }
.wide { width: 100%; }

/* Usage report (/admin) */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 16px 0 20px;
}
.stats div {
  background: var(--drop-bg);
  border-radius: 14px;
  padding: 12px 14px;
}
.stats strong {
  display: block;
  font-size: 1.6rem;
}
.stats span {
  color: var(--muted);
  font-size: 0.9rem;
}
.table-wrap {
  overflow-x: auto;
}
.usage {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.usage th,
.usage td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.usage th {
  color: var(--muted);
  font-weight: 700;
}
.usage .num {
  text-align: right;
}

/* Plan choices on the account page */
.plans { display: flex; flex-direction: column; gap: 12px; margin: 12px 0 20px; }
.plan-option {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
}
.plan-option.best { border-color: var(--accent); }
.plan-option .price { font-size: 1.25rem; font-weight: 700; }
.plan-option small { color: var(--muted); margin-bottom: 8px; }
.plan-option .badge {
  position: absolute;
  top: -11px;
  right: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
}
