/* Territory War result and resilience states. Primary student viewport: 1194 × 834 landscape. */
body.quiz-room-active[data-quiz-mode="territory_war"] #quizStudentTerritory {
  position: relative;
}

.territory-decision-note {
  display: grid;
  gap: 4px;
  padding: 12px 13px;
  border: 1px solid #e2a23b;
  border-left-width: 4px;
  border-radius: 8px;
  color: #6d4307;
  background: #fff8e7;
}

.territory-decision-note strong {
  color: #18385f;
  font-size: 16px;
}

.territory-decision-note span {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

body.quiz-room-active[data-quiz-mode="territory_war"] #quizStudentTerritoryBoard .quiz-territory-cell.can-claim {
  border-color: #d98200;
  outline-color: #f3a51b;
  background: #fff0c9;
  box-shadow: 0 0 0 7px rgb(245 158 11 / 24%);
}

body.quiz-room-active[data-quiz-mode="territory_war"] #quizStudentTerritoryBoard .quiz-territory-cell.is-resolving {
  border-color: #b96900;
  outline-color: #e98b00;
  background: #ffd36f;
  box-shadow: 0 0 0 9px rgb(234 139 0 / 24%);
}

.territory-recovery-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(248 247 242 / 72%);
  backdrop-filter: blur(3px) saturate(0.8);
}

.territory-recovery-overlay[hidden] {
  display: none;
}

.territory-recovery-dialog {
  display: grid;
  width: min(460px, 72vw);
  gap: 10px;
  padding: 30px 34px;
  border: 1px solid #d9c9b5;
  border-radius: 16px;
  color: #203650;
  text-align: center;
  background: #fffefa;
  box-shadow: 0 22px 60px rgb(32 54 80 / 18%);
}

.territory-recovery-spinner {
  margin: 0 auto 3px;
  color: #e39516;
  font-size: 34px;
  animation: territory-state-spin 1.1s linear infinite;
}

.territory-recovery-dialog > p {
  margin: 0;
  color: #7e8996;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.territory-recovery-dialog h4 {
  margin: 2px 0 0;
  color: #132b4a;
  font-size: 25px;
  line-height: 1.2;
}

.territory-recovery-dialog > span {
  color: #657284;
  font-size: 13px;
  line-height: 1.5;
}

.territory-recovery-dialog ol {
  display: grid;
  gap: 9px;
  margin: 8px 0;
  padding: 14px 20px;
  border-top: 1px solid #e7ded2;
  border-bottom: 1px solid #e7ded2;
  text-align: left;
  list-style: none;
}

.territory-recovery-dialog li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #345170;
  font-size: 13px;
  font-weight: 800;
}

.territory-recovery-dialog li i {
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border: 2px solid #2c76dc;
  border-radius: 50%;
  color: #2c76dc;
  font-size: 9px;
}

.territory-recovery-dialog li.is-complete i {
  border-color: #2cab63;
  color: #fff;
  background: #2cab63;
}

.territory-recovery-action {
  min-height: 48px;
  border: 1px solid #1e65ca;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  background: #1769df;
}

.territory-recovery-dialog small {
  color: #788595;
  font-size: 11px;
}

.territory-result-shell {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 4px 18px 0;
  color: #172e49;
  background: #fffefa;
}

.territory-result-shell[hidden] {
  display: none;
}

.territory-result-heading {
  flex: 0 0 auto;
  padding: 3px 0 0;
}

.territory-result-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.territory-result-profile img {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border: 2px solid #dcccb7;
  border-radius: 50%;
  object-fit: cover;
  background: #f3eee6;
}

.territory-result-profile p {
  margin: 0 0 3px;
  color: #1769df;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.territory-result-profile h4 {
  margin: 0;
  color: #111a24;
  font-size: clamp(25px, 2.6vw, 36px);
  line-height: 1.14;
}

.territory-result-profile span {
  color: #5f6e7e;
  font-size: 13px;
  font-weight: 700;
}

.territory-result-layout {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: 232px minmax(360px, 1.08fr) minmax(320px, 1fr);
  gap: 14px;
}

.territory-result-team-card,
.territory-result-map-card,
.territory-result-data > section {
  border: 1px solid #dcd4c9;
  border-radius: 10px;
  background: #fff;
}

.territory-result-team-card {
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 28px 25px;
  border-left: 6px solid var(--territory-result-team-color, #1769df);
}

.territory-result-team-card > span {
  color: var(--territory-result-team-color, #1769df);
  font-size: 15px;
  font-weight: 900;
}

.territory-result-team-card > strong {
  margin: 26px 0 20px;
  padding-bottom: 23px;
  border-bottom: 1px solid #ded7ce;
  color: var(--territory-result-team-color, #1769df);
  font-size: 34px;
  line-height: 1.08;
}

.territory-result-team-card > b {
  color: var(--territory-result-team-color, #1769df);
  font-size: clamp(42px, 5.6vw, 74px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.territory-result-team-card > small {
  margin-top: auto;
  color: #586a7f;
  font-size: 14px;
  font-weight: 900;
}

.territory-result-map-card {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 14px;
}

.territory-result-map-card .quiz-territory-board {
  width: 100%;
  max-height: 430px;
}

.territory-result-data {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: minmax(118px, auto) 1fr 1fr;
  gap: 10px;
}

.territory-result-data > section {
  min-height: 0;
  padding: 13px 16px;
}

.territory-result-data h5 {
  margin: 0 0 9px;
  color: #172e49;
  font-size: 15px;
}

.territory-result-team-comparison {
  display: grid;
  grid-template-columns: repeat(var(--territory-team-count, 3), minmax(0, 1fr));
}

.territory-result-team-comparison article {
  display: grid;
  gap: 3px;
  padding: 2px 11px;
  border-left: 1px solid #ddd7ce;
  text-align: center;
}

.territory-result-team-comparison article:first-child {
  border-left: 0;
}

.territory-result-team-comparison span {
  color: var(--territory-result-team-color, #1769df);
  font-size: 12px;
  font-weight: 900;
}

.territory-result-team-comparison strong {
  color: var(--territory-result-team-color, #1769df);
  font-size: 27px;
  line-height: 1;
}

.territory-result-team-comparison small {
  color: #728092;
  font-size: 10px;
  font-weight: 800;
}

.territory-result-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  height: calc(100% - 24px);
  margin: 0;
}

.territory-result-metrics.is-contribution {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.territory-result-metrics div {
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 0 7px;
  border-left: 1px solid #ddd7ce;
  text-align: center;
}

.territory-result-metrics div:first-child {
  border-left: 0;
}

.territory-result-metrics dt {
  grid-row: 2;
  color: #6c7989;
  font-size: 10px;
  font-weight: 800;
}

.territory-result-metrics dd {
  grid-row: 1;
  margin: 0;
  color: #1769df;
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.territory-result-save {
  display: flex;
  min-height: 43px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  border: 1px solid #d8d1c6;
  border-radius: 8px;
  color: #435a72;
  font-size: 13px;
  font-weight: 900;
  background: #fff;
}

.territory-result-save[data-state="confirmed"] {
  border-color: #9fd8b5;
  color: #13753d;
  background: #f2fbf5;
}

.territory-result-save[data-state="confirmed"] i {
  animation: none;
}

.territory-result-shell footer {
  display: flex;
  min-height: 54px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  color: #54667a;
  font-size: 12px;
  font-weight: 800;
}

.territory-result-shell footer a {
  display: inline-flex;
  min-width: 236px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 7px;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  text-decoration: none;
  background: #0f63e9;
}

.territory-result-shell footer a[aria-disabled="true"] {
  cursor: wait;
  opacity: 0.48;
}

body[data-territory-phase="finished"] #quizStudentTerritory > .quiz-territory-heading,
body[data-territory-phase="finished"] #quizStudentTerritory > .territory-student-stage {
  display: none;
}

body.quiz-room-active[data-quiz-mode="territory_war"][data-territory-phase="finished"] .quiz-classic-student-topbar {
  grid-template-columns: minmax(280px, 1fr) 52px auto;
}

body.quiz-room-active[data-quiz-mode="territory_war"][data-territory-phase="finished"] .quiz-classic-light-stats {
  display: none;
}

body.quiz-room-active[data-quiz-mode="territory_war"][data-territory-phase="finished"] .quiz-classic-light-identity {
  min-width: 118px;
}

body.quiz-room-active[data-quiz-mode="territory_war"][data-territory-phase="finished"] .quiz-classic-light-identity strong {
  display: block;
  white-space: nowrap;
}

@keyframes territory-state-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1050px) and (orientation: landscape) {
  .territory-result-shell {
    padding-inline: 10px;
  }

  .territory-result-layout {
    grid-template-columns: 185px minmax(310px, 1fr) minmax(285px, 0.9fr);
    gap: 9px;
  }

  .territory-result-team-card {
    padding: 21px 17px;
  }

  .territory-result-profile img {
    width: 54px;
    height: 54px;
  }

  .territory-result-data > section {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .territory-recovery-spinner,
  .territory-recovery-dialog li:not(.is-complete) i,
  .territory-result-save:not([data-state="confirmed"]) i {
    animation: none;
  }
}
