:root {
  --green: #008c45;
  --green-dark: #006b35;
  --green-light: #e8f4ed;
  --red: #cd212a;
  --red-dark: #a81920;
  --red-light: #fbeaec;
  --white: #ffffff;
  --ivory: #f5f6f2;
  --ink: #202522;
  --muted: #626a65;
  --border: #d9ded9;
  --shadow: 0 14px 36px rgba(22, 47, 32, 0.10);
  --radius: 20px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--ivory); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(0, 140, 69, 0.08), transparent 35%),
    radial-gradient(circle at bottom right, rgba(205, 33, 42, 0.06), transparent 30%),
    var(--ivory);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.tricolore {
  position: sticky;
  top: 0;
  z-index: 50;
  height: calc(9px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}
.tricolore span:nth-child(1) { background: var(--green); }
.tricolore span:nth-child(2) { background: var(--white); }
.tricolore span:nth-child(3) { background: var(--red); }

.app-header {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 22px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 5vw, 2.5rem); line-height: 1.05; color: var(--green-dark); }
h2 { font-size: clamp(1.3rem, 4vw, 1.75rem); }
.eyebrow { margin-bottom: 4px; color: var(--red); font-weight: 800; letter-spacing: 0.04em; }

.app-shell { max-width: 1040px; margin: 0 auto; padding: 14px 22px 42px; }
.view { animation: fade-in 180ms ease-out; }
.hidden { display: none !important; }

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card {
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loading-card, .error-card { padding: 52px 24px; text-align: center; max-width: 720px; margin: 48px auto; }
.spinner { width: 46px; height: 46px; margin: 0 auto 20px; border: 5px solid #d9e9df; border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.summary-card { background: var(--white); border: 1px solid var(--border); border-radius: 16px; padding: 18px 12px; text-align: center; }
.summary-card strong { display: block; color: var(--green-dark); font-size: 1.55rem; }
.summary-card span { color: var(--muted); font-size: 0.88rem; }

.settings-card, .tools-card, .hint-card { padding: clamp(20px, 5vw, 34px); margin-bottom: 18px; }
.settings-card h2, .tools-card h2, .hint-card h2 { color: var(--green-dark); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field > span { font-weight: 700; color: #364039; }
select, input[type="text"] {
  width: 100%;
  min-height: 48px;
  border: 1px solid #bfc8c1;
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
select:focus, input[type="text"]:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0, 140, 69, 0.14); }

.switch-field { display: flex; align-items: center; gap: 10px; min-height: 74px; cursor: pointer; font-weight: 650; }
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 48px; height: 28px; border-radius: 999px; background: #c8cfca; position: relative; transition: 150ms ease; flex: 0 0 auto; }
.switch::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: white; top: 3px; left: 3px; box-shadow: 0 2px 4px rgba(0,0,0,0.18); transition: 150ms ease; }
.switch-field input:checked + .switch { background: var(--green); }
.switch-field input:checked + .switch::after { transform: translateX(20px); }

.selection-info { padding: 10px 12px; border-radius: 10px; background: var(--green-light); color: var(--green-dark); font-weight: 700; }

.button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 90ms ease, filter 120ms ease, opacity 120ms ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.48; cursor: not-allowed; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { background: var(--green-dark); }
.button-danger { color: white; background: var(--red); }
.button-danger:hover { background: var(--red-dark); }
.button-secondary { color: var(--ink); background: white; border: 1px solid #bfc8c1; }
.button-secondary:hover { background: #f1f4f1; }
.button-large { width: 100%; min-height: 52px; font-size: 1.05rem; }
.button-row { display: flex; gap: 10px; justify-content: flex-end; }
.button-row.wrap { flex-wrap: wrap; justify-content: flex-start; }

.quiz-status { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--green-dark); font-weight: 800; margin: 2px 2px 8px; }
.progress-track { height: 9px; background: #dce6df; border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress-track span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), #19a95e); transition: width 220ms ease; }

.quiz-card { padding: clamp(22px, 6vw, 46px); text-align: center; min-height: 440px; display: flex; flex-direction: column; align-items: center; }
.question-meta { color: var(--red-dark); font-weight: 800; margin-bottom: 8px; }
.question-mode { color: var(--green-dark); font-size: 1.15rem; margin-bottom: 18px; }
.question-text { font-size: clamp(1.8rem, 8vw, 3.3rem); font-weight: 850; line-height: 1.12; white-space: pre-line; overflow-wrap: anywhere; margin: 8px 0 32px; }
.answer-area { width: min(100%, 680px); margin-top: auto; }
.answer-hint { color: var(--muted); }
.text-answer-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.choice-grid { display: grid; grid-template-columns: repeat(4, minmax(70px, 1fr)); gap: 10px; }
.choice-grid .button { color: var(--green-dark); background: white; border: 2px solid var(--green); min-height: 52px; font-size: 1.05rem; }
.choice-grid .button:hover { background: var(--green-light); }

.feedback { width: min(100%, 760px); border-radius: 12px; padding: 13px 16px; margin-top: 22px; font-weight: 850; }
.feedback.correct { color: var(--green-dark); background: var(--green-light); }
.feedback.wrong { color: var(--red-dark); background: var(--red-light); }
.answer-details { width: min(100%, 760px); color: #465149; line-height: 1.55; margin-top: 14px; white-space: pre-line; }
.quiz-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }

.report-card { padding: clamp(24px, 6vw, 46px); text-align: center; }
.report-numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 24px 0; }
.report-numbers > div { background: var(--ivory); border: 1px solid var(--border); border-radius: 14px; padding: 16px 8px; }
.report-numbers strong { display: block; color: var(--green-dark); font-size: 1.55rem; }
.report-numbers span { color: var(--muted); font-size: 0.82rem; }
.mistake-section { text-align: left; margin: 24px 0; }
.mistake-section h3 { color: var(--red-dark); }
.mistake-list { display: grid; gap: 8px; max-height: 42vh; overflow: auto; }
.mistake-item { padding: 12px; border-radius: 10px; background: var(--red-light); border-left: 4px solid var(--red); }
.mistake-item strong { color: var(--red-dark); }

.dialog-card { width: min(92vw, 540px); border: 0; border-radius: 18px; padding: 0; box-shadow: 0 22px 70px rgba(0,0,0,0.28); }
.dialog-card::backdrop { background: rgba(20, 30, 23, 0.52); backdrop-filter: blur(2px); }
.dialog-card form { padding: 26px; }
.dialog-card h2 { color: var(--green-dark); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: #17251c; color: white; border-radius: 12px; padding: 12px 18px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center; }

@media (max-width: 700px) {
  .app-header { padding: 17px 16px 4px; align-items: flex-start; }
  .app-shell { padding: 12px 14px 32px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  .quiz-status { font-size: 0.82rem; }
  .quiz-card { min-height: 470px; }
  .choice-grid { grid-template-columns: repeat(2, 1fr); }
  .report-numbers { grid-template-columns: repeat(2, 1fr); }
  .button-row { flex-direction: column-reverse; }
  .button-row .button { width: 100%; }
}

@media (max-width: 430px) {
  .app-header #installButton { font-size: 0.78rem; padding: 8px 10px; }
  .text-answer-row { grid-template-columns: 1fr; }
  .text-answer-row .button { width: 100%; }
  .quiz-actions .button { flex: 1; padding-left: 8px; padding-right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

.report-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}
