#app {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#app > * {
  width: min(100%, 560px);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 56px;
  padding: 0 150px 0 64px;
}

h1 {
  font-size: clamp(24px, 7vw, 34px);
  letter-spacing: 3px;
  font-weight: 800;
}

h1 span {
  color: #4cc38a;
}

.tools {
  position: absolute;
  right: 0;
  display: flex;
  gap: 8px;
}

.tools button,
.modes button,
.regions button {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  min-width: 44px;
  height: 44px;
  font-size: 18px;
  font-weight: 700;
}

.modes,
.regions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.modes button {
  padding: 0 18px;
  font-size: 15px;
}

.regions button {
  padding: 0 14px;
  height: 38px;
  font-size: 14px;
}

.modes button.on,
.regions button.on {
  background: #f1f3f8;
  color: #14213d;
}

/* --- flag --- */
.flagbox {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  height: min(32vh, 280px);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.frame {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

#flag-canvas {
  display: block;
  height: min(24vh, 210px);
  max-width: min(80vw, 480px);
  object-fit: contain;
}

.tiles {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.tiles div {
  background: #2c3d6b;
  border: 1px solid #14213d;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.35);
  transition: opacity 0.5s, transform 0.5s;
}

.tiles div.open {
  opacity: 0;
  transform: scale(0.6) rotate(8deg);
}

.flagbox.won .frame {
  box-shadow: 0 0 0 4px #4cc38a, 0 6px 18px rgba(0, 0, 0, 0.45);
}

.flagbox.lost .frame {
  box-shadow: 0 0 0 4px #e5484d, 0 6px 18px rgba(0, 0, 0, 0.45);
}

#q-flag {
  font-size: min(24vh, 200px);
  line-height: 1;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
}

#q-flag.new {
  animation: pop 0.35s both;
}

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* --- guessing --- */
#guess-form {
  display: flex;
  gap: 8px;
}

.field {
  flex: 1;
  position: relative;
}

#guess {
  width: 100%;
  height: 52px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: #0d1730;
  color: inherit;
  padding: 0 14px;
  font-size: 18px;
  outline: none;
}

#guess:focus {
  border-color: #4cc38a;
}

#guess-form > button,
.end-buttons button,
#q-again,
dialog button {
  border: none;
  border-radius: 12px;
  background: #4cc38a;
  color: #0b1a14;
  font-weight: 800;
  font-size: 17px;
  height: 52px;
  padding: 0 18px;
}

#suggest {
  list-style: none;
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: 56px;
  max-height: 260px;
  overflow-y: auto;
  touch-action: pan-y;
  background: #f1f3f8;
  color: #14213d;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#suggest li {
  padding: 12px 14px;
  font-size: 17px;
  border-bottom: 1px solid #dde2ee;
}

#suggest li.active,
#suggest li:active {
  background: #c9f0dc;
}

#rows,
.example {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#rows li,
.example li {
  display: grid;
  grid-template-columns: 1fr 92px 44px 60px;
  gap: 6px;
  height: 44px;
}

#rows li > *,
.example li > * {
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}

#rows li > :first-child,
.example li > :first-child {
  justify-items: start;
  padding-left: 12px;
}

#rows li.empty > * {
  background: rgba(255, 255, 255, 0.04);
}

#rows li.new > * {
  animation: flip 0.45s both;
}

#rows li.new > :nth-child(2) { animation-delay: 0.08s; }
#rows li.new > :nth-child(3) { animation-delay: 0.16s; }
#rows li.new > :nth-child(4) { animation-delay: 0.24s; }

#rows li.correct > * {
  background: #2b7a55;
}

@keyframes flip {
  from { transform: rotateX(90deg); }
  to { transform: rotateX(0); }
}

#end,
#q-end {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#end > *,
#q-end > * {
  width: 100%;
}

#end-msg,
#q-end-msg {
  font-size: 21px;
  font-weight: 800;
}

#bonus h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

#bonus-summary {
  font-size: 16px;
  font-weight: 700;
}

.end-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

#share-btn {
  background: #f1f3f8;
}

#toast {
  text-align: center;
  font-size: 15px;
  opacity: 0.85;
}

/* --- multiple choice (quiz and bonus rounds) --- */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choices button {
  min-height: 64px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.choices button svg {
  display: block;
  width: 100%;
  height: min(16vh, 130px);
}

.choices button svg path {
  fill: #f1f3f8;
}

.choices button:active {
  transform: scale(0.97);
}

.choices button:disabled {
  opacity: 0.45;
}

.choices button.right {
  background: #2b7a55;
  border-color: #4cc38a;
  opacity: 1;
}

.choices button.wrong {
  background: #8f2d31;
  border-color: #e5484d;
  opacity: 1;
}

.status {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 700;
  opacity: 0.85;
}

#q-feedback {
  min-height: 22px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

#q-missed {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#q-missed li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 16px;
  text-align: left;
}

#q-missed li span {
  font-size: 34px;
}

#q-missed li small {
  margin-left: auto;
  opacity: 0.6;
}

/* --- dialogs --- */
dialog {
  margin: auto;
  width: min(92vw, 440px);
  border: none;
  border-radius: 18px;
  background: #1d2c52;
  color: inherit;
  padding: 22px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog h2 {
  margin-bottom: 12px;
}

dialog h3 {
  margin: 18px 0 8px;
  font-size: 15px;
}

dialog p {
  margin-bottom: 10px;
  line-height: 1.4;
}

dialog .example {
  margin: 12px 0;
}

dialog .small {
  font-size: 13px;
  opacity: 0.7;
}

dialog form {
  margin-top: 16px;
  text-align: right;
}

.toggle {
  display: flex;
  gap: 14px;
  align-items: center;
  line-height: 1.3;
}

.toggle input {
  width: 26px;
  height: 26px;
  accent-color: #4cc38a;
}

.toggle small {
  opacity: 0.7;
}

.numbers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
  font-size: 12px;
}

.numbers b {
  display: block;
  font-size: 28px;
}

#st-dist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  margin-bottom: 10px;
}

#st-dist li {
  display: flex;
  gap: 8px;
  align-items: center;
}

#st-dist span {
  background: #4c5a80;
  min-width: 24px;
  padding: 2px 6px;
  text-align: right;
  font-weight: 700;
  border-radius: 4px;
}

#st-dist li.today span {
  background: #4cc38a;
  color: #0b1a14;
}

@media (max-width: 430px) {
  header {
    padding: 0 150px 0 56px;
    justify-content: flex-start;
  }

  #rows li,
  .example li {
    grid-template-columns: 1fr 78px 38px 50px;
  }
}
