:root {
  --bg: #f8f6f2;
  --fg: #1a1a1a;
  --accent: #2d6a4f;
  --accent2: #bc6c25;
  --card: #fff;
  --err: #9b2226;
  --ok: #1b4332;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  font-size: 1.05rem;
}

.wrap { max-width: 52rem; margin: 0 auto; padding: 0 1rem; }
.header {
  background: var(--card);
  border-bottom: 3px solid var(--accent);
  padding: 0.75rem 0;
}
.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.header h1 { margin: 0; font-size: 1.35rem; }
.lang-switch {
  font-size: 0.95rem;
  font-weight: 600;
}
.lang-switch a { color: var(--accent); text-decoration: none; }
.lang-switch a.is-active { color: var(--fg); text-decoration: underline; }
.lang-sep { color: #999; margin: 0 0.15rem; }
.header h1 a { color: var(--accent); text-decoration: none; }
.nav { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.75rem; }
.nav a { color: var(--accent2); font-weight: 600; }

.main { padding: 1.5rem 1rem 3rem; }

.card {
  background: var(--card);
  padding: 1.25rem 1.5rem;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  margin-bottom: 1rem;
}

.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.error { background: #ffe5e5; color: var(--err); }
.flash.ok { background: #e8f5e9; color: var(--ok); }

label { display: block; margin: 0.75rem 0 0.25rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%; max-width: 24rem;
  padding: 0.5rem 0.65rem;
  font-size: 1rem;
  border: 2px solid #ccc;
  border-radius: 8px;
}

button, .btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.55rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
.btn-secondary { background: #6c757d; }
.btn-danger { background: var(--err); }
.admin-delete-form { display: inline; margin: 0; }
.admin-delete-form button { margin-top: 0; }

.question { font-size: 1.35rem; font-weight: 700; }
.explain { margin-top: 1rem; padding: 1rem; background: #fff8e7; border-left: 4px solid var(--accent2); border-radius: 4px; white-space: pre-wrap; }

.explain.explain-text { margin-top: 0.75rem; }

/* European long division: left column = dividend + work (same grid); right = | divisor / quotient */
.eu-long-division {
  --eu-gutter: 0.75ch;
  --eu-cell: 1.2ch;
  margin: 0.75rem 0 0.5rem;
  padding: 1rem 1.15rem 1rem;
  border-radius: 10px;
  border: 1px solid #b8d4e8;
  background-color: #f3f9fd;
  background-image:
    linear-gradient(rgba(100, 140, 180, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 140, 180, 0.12) 1px, transparent 1px);
  background-size: 14px 14px;
  background-position: -1px -1px;
  overflow-x: auto;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  color: var(--fg);
}

.eu-ld-sheet {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.45rem;
}

.eu-ld-left {
  flex: 0 0 auto;
  width: calc(var(--eu-gutter) + var(--n) * var(--eu-cell));
  max-width: 100%;
  min-width: 0;
}

.eu-ld-right {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding-top: 0.05rem;
}

.eu-ld-r-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.3rem;
}

.eu-ld-r-row1 .eu-ld-s {
  border-bottom: 2px solid var(--fg);
  padding: 0 0.35rem 0.12rem;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.15;
  min-width: 2ch;
  text-align: center;
}

.eu-ld-r-v {
  padding: 0 0.15rem 0.12rem;
  font-weight: 400;
  color: #555;
  line-height: 1;
  border-bottom: 2px solid var(--fg);
}

.eu-ld-r-row2 .eu-ld-r-v {
  align-self: stretch;
  border-bottom: none;
  padding-bottom: 0;
}

.eu-ld-r-row2 {
  align-items: flex-start;
}

.eu-ld-dig-block {
  --n: 3;
  display: block;
  width: 100%;
}

.eu-ld-dig-row {
  display: grid;
  grid-template-columns: var(--eu-gutter) repeat(var(--n, 3), minmax(0, var(--eu-cell)));
  align-items: end;
  justify-items: center;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.5;
}

.eu-ld-dig-row .eu-g {
  width: var(--eu-gutter);
  min-width: var(--eu-gutter);
  max-width: var(--eu-gutter);
  justify-self: end;
  text-align: right;
  padding-right: 0.05rem;
  color: #333;
  font-weight: 700;
  box-sizing: border-box;
}

.eu-ld-dig-row .eu-c {
  width: var(--eu-cell);
  min-width: var(--eu-cell);
  max-width: var(--eu-cell);
  text-align: center;
  box-sizing: border-box;
  font-variant-numeric: tabular-nums;
  padding: 0;
}

.eu-ld-row-sub .eu-c {
  color: #444;
}

.eu-ld-dividend-line {
  border-bottom: 2px solid var(--fg);
  padding-bottom: 0.12rem;
  margin-bottom: 0.35rem;
}

.eu-ld-qblock {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.5ch;
}

.eu-ld-hrule {
  display: block;
  width: 100%;
  min-width: 2.5ch;
  border: none;
  border-top: 2px solid var(--fg);
  margin: 0 0 0.12rem;
}

.eu-ld-q {
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.15;
  text-align: center;
}

.eu-ld-work {
  margin-top: 0;
  padding-top: 0.2rem;
}

.eu-ld-step {
  margin-bottom: 0.55rem;
}

.eu-ld-step:last-child {
  margin-bottom: 0;
}

.eu-ld-step-line-grid {
  height: 0;
  margin: 0.08rem 0 0.1rem;
  border: none;
  border-top: 2px solid var(--fg);
  width: calc(var(--sw) * var(--eu-cell));
  margin-left: calc(var(--eu-gutter) + var(--sc) * var(--eu-cell));
  box-sizing: border-box;
}

.eu-ld-check {
  margin: 0.85rem 0 0;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 0.95rem;
  font-style: normal;
  font-weight: 600;
  color: #333;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}

.question-hint { font-size: 0.95rem; color: #555; margin-top: 0.35rem; font-weight: 500; }

.practice-qr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; align-items: end; max-width: 28rem; margin-top: 0.5rem; }
.practice-qr label { margin-top: 0.5rem; }
.practice-qr input { margin-top: 0.15rem; }
@media (max-width: 30rem) {
  .practice-qr { grid-template-columns: 1fr; }
}

table.stats { width: 100%; border-collapse: collapse; }
table.stats th, table.stats td { border: 1px solid #ddd; padding: 0.4rem 0.5rem; text-align: left; }

.footer { padding: 1rem; color: #666; font-size: 0.9rem; }

.login-extra { margin-top: 1rem; font-size: 0.95rem; }
.login-extra a { color: var(--accent2); }

.verify-resend {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  background: #f0f7f4;
  border-radius: 8px;
  border: 1px solid #c8e6d9;
}
.verify-resend p { margin: 0 0 0.5rem; }
.verify-resend button { margin-top: 0.5rem; }
