@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap");
:root {
  --paper: #f5f3ed;
  --ink: #18332d;
  --muted: #6f7971;
  --line: #d9ddd3;
  --green: #234d3d;
  --lime: #d5ed88;
  --red: #a13b32;
  --blue: #dce7ef;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
select {
  font: inherit;
}
button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  color: inherit;
}
button:disabled {
  cursor: default;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #6086b0;
  outline-offset: 3px;
}
a {
  color: inherit;
}
button {
  border: 0;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1,
h2,
h3,
.number,
.brand {
  font-family: "Space Grotesk", system-ui, sans-serif;
}
#app {
  max-width: 1040px;
  margin: auto;
  padding: env(safe-area-inset-top) 24px max(25px, env(safe-area-inset-bottom));
}
header {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.brand {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -1px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand img {
  width: 24px;
  height: 29px;
}
.account {
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 10px 16px;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
}
.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
}
.hero {
  display: grid;
  grid-template-columns: 1fr 0.9fr;
  gap: 32px;
  align-items: center;
  padding: 54px 0 38px;
}
.hero h1 {
  font-size: clamp(44px, 6vw, 64px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -3px;
  margin: 18px 0;
}
.hero p {
  line-height: 1.6;
  color: var(--muted);
  max-width: 330px;
  font-size: 15px;
}
.hero-art {
  height: 230px;
  position: relative;
  background-image: radial-gradient(#c5cec1 1px, transparent 1px);
  background-size: 16px 16px;
}
.flag-print {
  position: absolute;
  width: 57%;
  height: 64%;
  padding: 13px;
  background: #fff;
  box-shadow: 0 6px 14px #18332d15;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e1e2d9;
  transform: rotate(-12deg);
  top: 20px;
  left: 10px;
}
.flag-print:nth-child(2) {
  transform: rotate(9deg);
  left: 38%;
  top: 70px;
}
.flag-print img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 14px;
  gap: 10px;
}
.section-title h2 {
  font-size: 21px;
  letter-spacing: -0.6px;
}
.text-button {
  font-size: 12px;
  background: transparent;
  padding: 10px 0;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.stats {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #eeeee5;
}
.stat b {
  font-size: 23px;
  font-family: "Space Grotesk";
  display: block;
  font-weight: 500;
}
.stat span {
  font-size: 11px;
  color: var(--muted);
}
.meter {
  height: 5px;
  background: #dce1d1;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 14px;
}
.meter span {
  display: block;
  height: 100%;
  background: var(--green);
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.mode {
  padding: 22px;
  text-align: left;
  border-radius: 18px;
  background: #e6eadc;
  position: relative;
  min-height: 190px;
  border: 1px solid #dbe1ce;
  transition: transform 0.15s;
}
.mode:nth-child(2) {
  background: #e2e9ed;
  border-color: #d5dee3;
}
.mode:nth-child(3) {
  background: #eee5d9;
  border-color: #e4d8c8;
}
.mode:hover {
  transform: translateY(-3px);
}
.mode-symbol {
  display: block;
  font: 500 24px "Space Grotesk";
  margin-bottom: 26px;
}
.mode h3 {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.6px;
}
.mode p {
  font-size: 12px;
  color: #5d6b60;
  line-height: 1.5;
  margin-top: 7px;
}
.mode .arrow {
  position: absolute;
  top: 23px;
  right: 22px;
}
.filters {
  display: flex;
  gap: 8px;
  overflow: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 25px;
  background: transparent;
  font-size: 12px;
}
.chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.footer {
  margin-top: 35px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}
.notice {
  font-size: 12px;
  color: var(--muted);
  padding: 14px 0;
  line-height: 1.5;
}
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
  gap: 12px;
}
.back {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 23px;
}
.quiz-meta {
  text-align: center;
}
.quiz-meta .eyebrow {
  font-size: 10px;
}
.quiz-meta p {
  font-size: 13px;
  margin-top: 5px;
}
.round-pill {
  border-radius: 20px;
  padding: 9px 12px;
  background: #e5eadd;
  font-size: 12px;
}
.quiz-progress {
  height: 3px;
  background: var(--line);
}
.quiz-progress div {
  height: 100%;
  background: var(--green);
  transition: width 0.2s;
}
.question {
  text-align: center;
  margin-top: 28px;
  font-size: 13px;
  color: var(--muted);
}
.flag-stage {
  height: 290px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 34px 10px;
  position: relative;
}
.flag-stage img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 8px 9px #18332d12);
}
.flag-stage h1 {
  font-size: clamp(30px, 6vw, 49px);
  letter-spacing: -1.5px;
  font-weight: 500;
  max-width: 600px;
}
.quiz-shell {
  max-width: 650px;
  margin: auto;
}
.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.answer {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fffef9;
  padding: 18px 14px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.3;
}
.answer.flag-answer {
  height: 126px;
  padding: 20px;
}
.flag-answer img {
  max-height: 100%;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.answer.correct {
  background: #e4efcb;
  border: 2px solid #57783e;
}
.answer.wrong {
  background: #f2dfd8;
  border: 2px solid #bb7263;
  opacity: 0.7;
}
.type-form {
  display: flex;
  gap: 8px;
}
.type-form input,
.search {
  min-width: 0;
  width: 100%;
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 17px;
  font-size: 17px;
  color: var(--ink);
}
.primary {
  background: var(--green);
  color: white;
  border-radius: 12px;
  padding: 16px 22px;
  font-weight: 600;
  font-size: 15px;
}
.primary:disabled {
  opacity: 0.6;
}
.feedback {
  min-height: 72px;
  padding: 18px 2px 8px;
  font-size: 14px;
  line-height: 1.5;
}
.feedback.success {
  color: #345b23;
}
.feedback.error {
  color: var(--red);
}
.quiz-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 15px;
}
.hint {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  background: transparent;
  font-size: 13px;
}
.hint-panel {
  background: #e9eddd;
  border-radius: 12px;
  padding: 15px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 16px;
}
.summary {
  text-align: center;
  padding: 60px 0 30px;
}
.summary h1 {
  font-size: 43px;
  letter-spacing: -2px;
  margin: 15px 0;
}
.summary p {
  color: var(--muted);
  line-height: 1.6;
}
.summary .number {
  font-size: 80px;
  color: var(--green);
  letter-spacing: -6px;
  margin: 30px 0;
}
.summary-actions {
  display: grid;
  gap: 12px;
  max-width: 350px;
  margin: 28px auto;
}
.library {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
}
.country-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 16px;
  background: #fffef9;
  text-align: left;
}
.country-card img {
  height: 70px;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: auto auto 15px;
}
.country-card h3 {
  font-size: 14px;
  line-height: 1.4;
}
.country-card p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: #18332d80;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal {
  background: var(--paper);
  border-radius: 22px;
  padding: 25px;
  max-width: 440px;
  width: 100%;
  max-height: 90dvh;
  overflow: auto;
}
.modal h2 {
  margin: 8px 0 16px;
  font-size: 28px;
  letter-spacing: -1px;
}
.modal p {
  font-size: 14px;
  line-height: 1.7;
  margin: 15px 0;
}
.modal img.detail-flag {
  max-width: 100%;
  max-height: 220px;
  display: block;
  margin: 25px auto;
}
.close {
  float: right;
  border-radius: 50%;
  background: #e3e7dc;
  width: 36px;
  height: 36px;
  font-size: 22px;
}
.loading {
  padding: 70px 20px;
}
.review-list {
  text-align: left;
  margin: 25px 0;
  border-top: 1px solid var(--line);
}
.review-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.review-row img {
  width: 45px;
  height: 30px;
  object-fit: contain;
}
.review-row small {
  margin-left: auto;
  color: var(--muted);
}
@media (max-width: 600px) {
  #app {
    padding-left: 20px;
    padding-right: 20px;
  }
  header {
    height: 70px;
  }
  .hero {
    padding: 30px 0 24px;
    gap: 12px;
    grid-template-columns: 1.2fr 0.8fr;
  }
  .hero h1 {
    font-size: 44px;
    letter-spacing: -2.5px;
  }
  .hero p {
    font-size: 13px;
  }
  .hero-art {
    height: 170px;
    margin-right: -5px;
  }
  .flag-print {
    width: 85%;
    height: 54%;
    left: -5px;
    top: 8px;
    padding: 9px;
  }
  .flag-print:nth-child(2) {
    left: 16%;
    top: 76px;
    transform: rotate(9deg);
  }
  .eyebrow {
    font-size: 9px;
    letter-spacing: 1.5px;
  }
  .mode-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .mode {
    min-height: 104px;
    padding: 22px 20px 22px 76px;
  }
  .mode-symbol {
    position: absolute;
    left: 22px;
    top: 33px;
    font-size: 22px;
    margin: 0;
  }
  .mode h3 {
    font-size: 20px;
  }
  .mode p {
    font-size: 12px;
    margin-top: 4px;
    padding-right: 18px;
  }
  .mode .arrow {
    top: 41px;
    right: 20px;
  }
  .section-title {
    margin-top: 24px;
  }
  .stats {
    padding: 15px 18px;
  }
  .flag-stage {
    height: clamp(190px, 33dvh, 290px);
  }
  .question {
    margin-top: 22px;
  }
  .answer {
    min-height: 80px;
  }
  .library {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .footer {
    margin-top: 26px;
  }
  .hero-art:after {
    content: "197 FLAGS";
    position: absolute;
    bottom: -9px;
    right: 0;
    font-size: 8px;
    letter-spacing: 2px;
    color: var(--muted);
  }
  .type-quiz .flag-stage {
    height: clamp(130px, 28dvh, 230px);
    padding: 25px 10px;
  }
  .type-quiz .feedback {
    min-height: 58px;
  }
  .type-quiz .question {
    margin-top: 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Quiz geometry is independent of answer state and intrinsic SVG dimensions. */
.play-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #e7e9df;
  padding: 4px;
  border-radius: 14px;
  gap: 4px;
}
.play-switch button {
  padding: 13px;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: 14px;
}
.play-switch button.active {
  background: var(--green);
  color: white;
}
.play-description {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  margin: 13px 0 20px;
  min-height: 20px;
}
.scope-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.scope-controls label,
.sort-label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  min-width: 0;
}
.scope-controls select,
.sort-label select {
  appearance: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef9;
  color: var(--ink);
  padding: 12px 9px;
  width: 100%;
  min-width: 0;
  font-size: 13px;
}
.scope-controls select:disabled {
  opacity: 0.6;
}
.scope-count {
  font-size: 11px;
  color: var(--muted);
  margin: 10px 0 18px;
}
.best-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  margin-top: 12px;
  color: var(--green);
}
.library-tools {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.library-tools .search {
  flex: 1;
  width: 0;
  min-width: 0;
}
.sort-label {
  width: 130px;
  flex: none;
}
.score-total {
  font-size: 30px;
  letter-spacing: -1px;
  color: var(--muted);
}
.personal-record {
  margin-top: 12px !important;
}
.life-icons {
  display: flex;
  gap: 3px;
  justify-content: center;
}
.life-icons svg {
  display: block;
  stroke: #a34c42;
  stroke-width: 1.5;
}
.life-icons .full svg {
  fill: #b8574b;
}
.life-icons .empty svg {
  fill: none;
  opacity: 0.35;
}
body.quiz-playing {
  overflow: hidden;
  overscroll-behavior: none;
}
body.quiz-playing #app {
  height: var(--quiz-height, 100svh);
  padding: env(safe-area-inset-top) 20px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.quiz-playing .quiz-shell {
  height: 100%;
  max-width: 650px;
  display: grid;
  grid-template-rows: 64px 3px 36px minmax(48px, 1fr) 252px 100px 58px;
  gap: 0;
}
.quiz-playing .quiz-header {
  height: auto;
  min-width: 0;
}
.quiz-playing .quiz-meta {
  min-width: 0;
  max-width: 65%;
}
.quiz-playing .quiz-meta p {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.quiz-playing .round-pill {
  min-width: 70px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  padding: 8px 10px;
  text-align: center;
}
.quiz-playing .question {
  margin: 0;
  align-self: center;
  font-size: 12px;
}
.quiz-playing .flag-stage {
  height: auto;
  min-height: 0;
  padding: 18px 10px;
  overflow: hidden;
}
.quiz-playing .flag-stage > img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 7px #18332d10);
}
.quiz-playing .flag-stage h1 {
  font-size: clamp(26px, 5vw, 40px);
  line-height: 1.05;
}
.quiz-playing .answers {
  height: 252px;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  min-height: 0;
}
.quiz-playing .answer {
  height: 100%;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
  padding: 10px;
  font-size: 14px;
  box-sizing: border-box;
  border: 2px solid var(--line);
  -webkit-appearance: none;
  appearance: none;
  opacity: 1;
}
.quiz-playing .answer.flag-answer {
  padding: 10px;
}
.quiz-playing .flag-frame {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.quiz-playing .flag-frame img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.quiz-playing .answer.correct {
  border-color: #57783e;
  background: #e4efcb;
}
.quiz-playing .answer.wrong {
  border-color: #bb7263;
  background: #f2dfd8;
}
.quiz-playing .answer.wrong img {
  opacity: 0.6;
}
.quiz-feedback {
  height: 100px;
  overflow: auto;
  min-height: 0;
  padding: 10px 0;
  scrollbar-width: thin;
}
.quiz-playing .feedback {
  min-height: 0;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.45;
}
.quiz-playing .hint-panel {
  margin: 7px 0 0;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 10px;
}
.quiz-playing [hidden] {
  display: none !important;
}
.quiz-playing .quiz-actions {
  height: 58px;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 144px;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
}
.learning-actions {
  display: flex;
  gap: 7px;
  align-items: center;
}
.quiz-playing .hint {
  padding: 11px 14px;
  font-size: 12px;
}
.quiz-playing #next {
  width: 144px;
  min-height: 46px;
  padding: 12px 8px;
  font-size: 14px;
}
.quiz-playing #next:disabled {
  background: #e5e8df;
  color: #7a847a;
  opacity: 1;
}
.challenge-rule {
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.quiz-playing .type-quiz {
  grid-template-rows: 64px 3px 36px minmax(60px, 1fr) 54px 108px 58px;
}
.quiz-playing .type-form {
  height: 54px;
  min-height: 0;
}
.quiz-playing .type-form input {
  height: 54px;
  padding: 12px 14px;
}
.quiz-playing .type-form button {
  padding: 12px 18px;
}
.keyboard-open .type-quiz {
  grid-template-rows: 42px 2px 24px minmax(36px, 1fr) 48px 64px 48px;
}
.keyboard-open .quiz-header .back {
  height: 34px;
  width: 34px;
}
.keyboard-open .quiz-meta .eyebrow {
  font-size: 8px;
}
.keyboard-open .quiz-meta p {
  margin-top: 2px;
  font-size: 10px;
}
.keyboard-open .flag-stage {
  padding: 6px;
}
.keyboard-open .type-form,
.keyboard-open .type-form input {
  height: 48px;
}
.keyboard-open .quiz-feedback {
  height: 64px;
  padding: 6px 0;
}
.keyboard-open .quiz-actions {
  height: 48px;
}
.keyboard-open #next {
  min-height: 40px;
}
.keyboard-open .hint {
  padding: 9px 12px;
}
@media (max-height: 660px) {
  .quiz-playing .quiz-shell:not(.type-quiz) {
    grid-template-rows: 44px 3px 26px minmax(28px, 1fr) 220px 82px 50px;
  }
  .quiz-playing .answers {
    height: 220px;
  }
  .quiz-playing .quiz-feedback {
    height: 82px;
  }
  .quiz-playing .quiz-meta p {
    font-size: 10px;
  }
  .quiz-playing .back {
    width: 36px;
    height: 36px;
  }
  .quiz-playing .question {
    font-size: 11px;
  }
}
@media (min-width: 601px) {
  body.quiz-playing #app {
    max-height: 900px;
  }
  .mode .best-label {
    margin-top: 14px;
  }
  .quiz-playing .quiz-shell {
    grid-template-rows: 70px 3px 40px minmax(70px, 1fr) 270px 108px 64px;
  }
  .quiz-playing .answers {
    height: 270px;
  }
  .scope-controls {
    max-width: 650px;
  }
  .library-tools {
    max-width: 650px;
  }
}

/* White flag fields remain visible without inset panels or extra artwork padding. */
.library-flag {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 94px;
  margin-bottom: 14px;
}
.country-card .library-flag img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  margin: 0;
  filter: drop-shadow(0 1px 1.5px #18332d30);
}
.quiz-playing .flag-frame img {
  filter: drop-shadow(0 1px 1.5px #18332d30);
}
.quiz-playing .flag-stage > img {
  filter: drop-shadow(0 1px 2px #18332d30);
}
.detail-flag {
  filter: drop-shadow(0 1px 2px #18332d30);
}
@media (min-width: 601px) {
  .quiz-playing .type-quiz {
    grid-template-rows: 70px 3px 40px minmax(60px, 1fr) 54px 108px 64px;
  }
}
body.quiz-playing.keyboard-open .quiz-feedback {
  height: 64px;
}
.quiz-playing .flag-frame {
  overflow: visible;
}
/* Name questions retain the large central flag from the original design. */
.quiz-playing .quiz-shell.name-quiz {
  grid-template-rows: 64px 3px 36px minmax(80px, 1fr) 172px 100px 58px;
}
.quiz-playing .name-quiz .answers {
  height: 172px;
}
@media (max-height: 660px) {
  .quiz-playing .quiz-shell.name-quiz {
    grid-template-rows: 44px 3px 26px minmax(50px, 1fr) 154px 82px 50px;
  }
  .quiz-playing .name-quiz .answers {
    height: 154px;
  }
}
@media (min-width: 601px) {
  .quiz-playing .quiz-shell.name-quiz {
    grid-template-rows: 70px 3px 40px minmax(100px, 1fr) 184px 108px 64px;
  }
  .quiz-playing .name-quiz .answers {
    height: 184px;
  }
}

.quiz-playing .answer.hint-excluded { opacity: 0.28; }
