:root { font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; }
body { margin: 0; background: #0b1220; color: #e9eefb; }
header { padding: 16px 18px; border-bottom: 1px solid #22304a; }
.topline { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title { font-size: 18px; font-weight: 800; }
.subtitle { font-size: 13px; opacity: .85; margin-top: 4px; }
.status { font-size: 14px; opacity: .9; }

.modeMenu { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.modeMenu button { padding: 9px 12px; }
.modeMenu button.active { outline: 2px solid #2b6cff; outline-offset: 2px; }

.langSelect { display: inline-flex; gap: 8px; align-items: center; }
.langLabel { font-size: 13px; opacity: .9; font-weight: 700; }
.langSelectControl {
  background: #1a2746;
  color: #e9eefb;
  border: 1px solid #22304a;
  border-radius: 10px;
  padding: 9px 10px;
  font-weight: 800;
  cursor: pointer;
}
.langSelectControl:focus { outline: 2px solid #2b6cff; outline-offset: 2px; }

.modeMenuToggle { display: none; }
.modeButtons { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

main { display: grid; grid-template-columns: 1.8fr 0.9fr; gap: 14px; padding: 14px; }
.card { background: #111a2e; border: 1px solid #22304a; border-radius: 16px; overflow: hidden; }

.mapWrap { padding: 0; }
#mapHost { width: 100%; touch-action: manipulation; }
#mapHost svg { width: 100%; height: auto; display: block; }

.panel { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.panel h2 { margin: 0; font-size: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
button { border: 0; border-radius: 10px; padding: 10px 12px; cursor: pointer; font-weight: 700; }
button.primary { background: #2b6cff; color: #fff; }
button.secondary { background: #1a2746; color: #e9eefb; border: 1px solid #22304a; }

.tiles { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px; }
.tile { background: #1a2746; border: 1px solid #22304a; border-radius: 999px; padding: 12px 16px; font-size: 16px; user-select: none; cursor: grab; }
.tile.selected { outline: 2px solid #2b6cff; outline-offset: 2px; }
.tile:active { cursor: grabbing; }

.hint { font-size: 13px; opacity: .85; padding: 0 10px 10px; }

/* Regions */
.region { fill: #18213a; stroke: #9fb0d1; stroke-opacity: .45; stroke-width: 1; }
.region.drop-hover { stroke-opacity: .9; stroke-width: 2; }
.region.done { stroke-opacity: .7; }

.label { font-size: 10px; fill: #f3f6ff; text-anchor: middle; paint-order: stroke; stroke: #0b1220; stroke-width: 2px; pointer-events: none; }

.win { display: none; padding: 10px; border-radius: 12px; background: #15254a; border: 1px solid #2b6cff; margin: 0 10px 10px; }
.win strong { font-size: 16px; }
.winNote { margin-top: 6px; opacity: .9; font-size: 14px; }

.hidden { display: none !important; }
.quizBox { display: flex; flex-direction: column; gap: 10px; }
.quizPrompt { font-size: 14px; opacity: .92; }
.quizOptions { display: grid; gap: 10px; flex: 1 1 auto; min-height: 0; overflow: auto; }
.quizBar { height: 10px; border-radius: 999px; border: 1px solid #22304a; background: #0b1220; overflow: hidden; }
.quizBarFill { height: 100%; width: 100%; background: #1fbf75; transform-origin: left center; }
.quizScoreBar { height: 10px; border-radius: 999px; border: 1px solid #22304a; background: #0b1220; overflow: hidden; }
.quizScoreBarFill { height: 100%; width: 0%; background: #ffd34a; transform-origin: left center; }
.quizFeedback { font-size: 13px; opacity: .9; min-height: 18px; }

.quizOptions button.optionCorrect { background: rgba(31, 191, 117, 0.25); border: 1px solid rgba(31, 191, 117, 0.85); }
.quizOptions button.optionWrong { background: rgba(255, 77, 77, 0.18); border: 1px solid rgba(255, 77, 77, 0.85); }

.huntTargetCard { padding: 10px 12px; border: 1px solid #22304a; border-radius: 12px; background: #0f1730; }
.huntTargetName { margin-top: 6px; font-size: 22px; font-weight: 900; letter-spacing: 0.2px; }

.region.quiz-target { stroke-opacity: .95; stroke-width: 2; }

/* --- Wide screens: keep the whole map inside the viewport --- */
@media (min-width: 981px) {
  html, body { height: 100%; }
  body { min-height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  main { flex: 1; min-height: 0; }
  .card { min-height: 0; }

  .mapWrap { height: 100%; display: flex; }
  #mapHost { flex: 1; min-height: 0; display: flex; }

  /* Scale SVG to the available area without stretching outside */
  #mapHost svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
  }

  /* Avoid page scroll; scroll panel content instead if it overflows */
  .panel { min-height: 0; overflow: auto; }
  .tiles { overflow: auto; }
}

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  #mapHost svg { max-height: 62vh; }
  .tiles { max-height: 32vh; overflow: auto; -webkit-overflow-scrolling: touch; }

  /* Games 2/3: fit everything into the viewport (no page scroll) */
  body[data-mode="quiz"],
  body[data-mode="hunt"] {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  body[data-mode="quiz"] main,
  body[data-mode="hunt"] main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1.12fr 0.88fr;
    gap: 12px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  body[data-mode="quiz"] .card,
  body[data-mode="hunt"] .card { min-height: 0; }

  body[data-mode="quiz"] .mapWrap,
  body[data-mode="hunt"] .mapWrap { height: 100%; display: flex; }
  body[data-mode="quiz"] #mapHost,
  body[data-mode="hunt"] #mapHost { flex: 1; min-height: 0; display: flex; }
  body[data-mode="quiz"] #mapHost svg,
  body[data-mode="hunt"] #mapHost svg { height: 100%; max-height: 100%; width: 100%; }

  body[data-mode="quiz"] .panel,
  body[data-mode="hunt"] .panel { min-height: 0; overflow: hidden; }

  /* Constrain quiz/hunt panels so only the options area scrolls */
  body[data-mode="quiz"] #quizPanel:not(.hidden),
  body[data-mode="hunt"] #huntPanel:not(.hidden) {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  body[data-mode="quiz"] .quizBox,
  body[data-mode="hunt"] .quizBox {
    flex: 1 1 auto;
    min-height: 0;
  }

  body[data-mode="quiz"] .quizOptions { min-height: 0; overflow: auto; }
}

@media (max-width: 520px) {
  header { padding: 12px 12px; }
  main { padding: 12px; }
  .tile { padding: 12px 14px; font-size: 16px; }
  button { width: 100%; }
  /* Keep language selector compact on mobile */
  .langSelect { width: auto; flex: 0 0 auto; }
  .langLabel { display: none; }
  .langSelectControl {
    width: auto;
    max-width: 140px;
    padding: 7px 10px;
    font-size: 13px;
  }
  .row { flex-direction: column; align-items: stretch; }
  #mapHost svg { max-height: 58vh; }

  /* Compact game selector: dropdown menu */
  .modeMenu { position: relative; gap: 8px; }
  .modeMenuToggle {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: auto;
    white-space: nowrap;
  }
  .modeMenuToggle::after { content: '▾'; opacity: .9; }

  .modeButtons {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 10;
    background: #0f1730;
    border: 1px solid #22304a;
    border-radius: 14px;
    padding: 8px;
    flex-direction: column;
    gap: 8px;
    min-width: min(92vw, 360px);
    box-shadow: 0 18px 45px rgba(0,0,0,.35);
  }
  .modeMenu.open .modeButtons { display: flex; }
  .modeButtons button { width: 100%; }
}
