:root {
  color-scheme: light;
  --ink: #172022;
  --muted: #667174;
  --line: #d8e1df;
  --paper: #f6f3ea;
  --panel: #fffdf8;
  --green: #1d6d5a;
  --green-dark: #10483d;
  --red: #b43d3d;
  --gold: #d7a528;
  --blue: #2a6f97;
  --globe-water: #dcebea;
  --globe-land: #d0b15f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #f6f3ea 0%, #e9f1ef 48%, #f8f6f0 100%);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: min(300px, calc(100vw - 32px));
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 20px 48px rgba(23, 32, 34, 0.18);
  transform: translateX(-105%);
  transition: transform 180ms ease;
}

.sidebar.open {
  transform: translateX(0);
}

.menu-toggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 30;
  display: grid;
  gap: 5px;
  place-content: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(23, 32, 34, 0.14);
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--green-dark);
}

.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(23, 32, 34, 0.28);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(23, 32, 34, 0.12);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 0.9rem;
}

.module-tabs,
.segmented {
  display: grid;
  gap: 8px;
}

.module-tabs button,
.segmented button,
.primary-action,
.secondary-action,
.answer-list button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.module-tabs button,
.segmented button {
  color: var(--ink);
  background: var(--panel);
}

.module-tabs .active,
.segmented .active {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.stats-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stats-panel span,
.stats-panel strong {
  display: block;
}

.stats-panel span {
  color: var(--muted);
}

.stats-panel strong {
  margin-top: 6px;
  font-size: 2rem;
}

.workspace {
  padding: 28px 28px 28px 82px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: end;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 4.2rem;
  line-height: 0.95;
  letter-spacing: 0;
}

.session-pill {
  min-width: 130px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  background: var(--panel);
}

.player-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.player-summary em {
  color: var(--green-dark);
  font-style: normal;
  font-weight: 800;
}

.module {
  display: none;
}

.module.active {
  display: block;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.controls-row .segmented {
  display: flex;
  flex-wrap: wrap;
}

.controls-row .segmented button {
  min-width: 86px;
  padding: 0 12px;
}

.primary-action {
  color: white;
  border-color: var(--green-dark);
  background: var(--green-dark);
  padding: 0 18px;
}

.secondary-action {
  color: var(--green-dark);
  background: var(--panel);
  padding: 0 18px;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.15fr) minmax(300px, 0.85fr);
  gap: 18px;
}

.flag-stage,
.answer-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.flag-stage {
  padding: 18px;
}

.round-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.flag-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 10;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, #f8f8f8 0 12px, #eef2f0 12px 24px);
  overflow: hidden;
}

.flag-frame img {
  max-width: 86%;
  max-height: 78%;
  border: 1px solid rgba(23, 32, 34, 0.18);
  box-shadow: 0 16px 38px rgba(23, 32, 34, 0.14);
}

.text-prompt {
  max-width: min(680px, 92%);
  color: var(--green-dark);
  font-size: 3.2rem;
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
}

.world-map {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  overflow: hidden;
  background: var(--globe-water);
  touch-action: none;
}

.world-map.dragging {
  cursor: grabbing;
}

.map-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform-origin: 0 0;
}

.flag-frame .map-canvas img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: fill;
  border: 0;
  box-shadow: none;
}

.map-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-overlay path {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1;
  pointer-events: all;
}

.map-overlay path.correct {
  fill: var(--green);
  fill-opacity: 0.72;
  stroke: var(--green-dark);
  stroke-width: 3;
}

.map-overlay path.target-outline {
  fill: transparent;
  stroke: var(--green);
  stroke-width: 8;
  stroke-linejoin: round;
}

.globe-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.map-controls button {
  min-width: 42px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green-dark);
  background: white;
  font-weight: 800;
  cursor: pointer;
}

.map-pin {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid white;
  border-radius: 50% 50% 50% 0;
  transform: translate(-50%, -100%) rotate(-45deg);
  box-shadow: 0 4px 14px rgba(23, 32, 34, 0.35);
}

.map-pin::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  inset: 50% auto auto 50%;
  border-radius: 50%;
  background: white;
  transform: translate(-50%, -50%);
}

.map-pin.user {
  background: var(--red);
}

.map-pin.target {
  background: var(--green);
}

.country-hint {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 74px;
  margin-top: 14px;
  color: var(--muted);
}

.country-hint img {
  width: 92px;
  height: 64px;
  object-fit: contain;
  opacity: 0.74;
}

.answer-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.answer-list {
  display: grid;
  gap: 10px;
}

.answer-list button {
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: white;
}

.help-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.map-mode-controls {
  grid-template-columns: 1fr;
}

.map-mode-controls button {
  min-height: 44px;
  padding: 8px 12px;
  white-space: normal;
  text-align: left;
}

.hint-stack {
  display: grid;
  gap: 8px;
}

.hint-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-weight: 750;
}

.hint-image {
  justify-self: center;
  max-width: 100%;
  object-fit: contain;
}

.hint-image.contour {
  width: min(220px, 100%);
  height: 136px;
}

.hint-image.flag {
  width: min(260px, 100%);
  height: 156px;
  border: 1px solid var(--line);
}

.answer-list button.correct {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.answer-list button.wrong {
  color: white;
  border-color: var(--red);
  background: var(--red);
}

.typed-answer {
  display: grid;
  gap: 10px;
}

.typed-answer label {
  color: var(--muted);
  font-weight: 700;
}

.typed-answer input,
.data-toolbar input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
}

.feedback {
  min-height: 52px;
  padding: 12px;
  border-radius: 8px;
  color: var(--muted);
  background: #eef2f0;
}

.feedback.good {
  color: var(--green-dark);
  background: #dceee8;
}

.feedback.bad {
  color: #7f2424;
  background: #f5dddd;
}

.hidden {
  display: none !important;
}

.data-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 440px) 1fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.data-toolbar span {
  color: var(--muted);
  font-size: 0.92rem;
}

.table-wrap {
  max-height: calc(100vh - 190px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e7efec;
}

td img {
  width: 70px;
  height: 44px;
  object-fit: contain;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}

.account-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

.admin-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2,
.profile-form h3 {
  margin: 0;
}

.auth-forms {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.profile-form {
  display: grid;
  gap: 9px;
}

.profile-form label {
  color: var(--muted);
  font-weight: 750;
}

.profile-form input,
.profile-form select,
.profile-form textarea,
.admin-player input,
.admin-player select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
}

.profile-form textarea {
  resize: vertical;
}

.avatar-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-choice {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.avatar-choice.active {
  border-color: var(--green);
  background: var(--green);
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.player-card strong,
.player-card span {
  display: block;
}

.player-card span,
.muted,
.portal-item span,
.ranking-row span {
  color: var(--muted);
}

.avatar-badge {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--paper);
  font-size: 1.5rem;
}

.portal-list {
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
}

.portal-item,
.ranking-row,
.ranking-group,
.admin-player {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.portal-item p {
  margin: 0;
}

.ranking-row {
  grid-template-columns: 36px minmax(120px, 1fr) auto minmax(110px, auto);
  align-items: center;
}

.ranking-group {
  gap: 8px;
}

.ranking-group > strong {
  color: var(--green-dark);
}

.admin-counts {
  display: grid;
  grid-template-columns: repeat(5, minmax(100px, 1fr));
  gap: 10px;
}

.admin-counts div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.admin-counts span,
.admin-counts strong {
  display: block;
}

.admin-counts span {
  color: var(--muted);
}

.admin-player {
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto auto;
  align-items: center;
}

.secondary-action.danger {
  color: #7f2424;
}

@media (max-width: 860px) {
  .sidebar {
    padding: 14px;
  }

  .module-tabs {
    grid-template-columns: 1fr;
  }

  .stats-panel {
    display: none;
  }

  .workspace {
    padding: 82px 18px 18px;
  }

  h1 {
    font-size: 2.4rem;
  }

  .topbar,
  .topbar-meta,
  .data-toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .profile-grid,
  .auth-forms,
  .admin-counts,
  .admin-player {
    grid-template-columns: 1fr;
  }

  .ranking-row {
    grid-template-columns: 32px 1fr auto;
  }

  .ranking-row span:last-child {
    grid-column: 2 / -1;
  }

  .text-prompt {
    font-size: 2.1rem;
  }
}
