:root {
  --rrr-blue: #149bd7;
  --rrr-ink: #102131;
  --rrr-muted: #5c6b78;
  --rrr-line: #d8e2ea;
  --rrr-green: #1d8f5a;
  --rrr-red: #d84f4f;
  --rrr-violet: #6d5fd0;
  --rrr-amber: #f3b23a;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  min-height: 0;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--rrr-ink);
  font-family: Arial, Helvetica, sans-serif;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.topbar {
  min-height: 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: #071018;
  color: #ffffff;
}

.brand,
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: inline-flex;
  flex: 0 0 auto;
  border-radius: 6px;
}

.brand img {
  display: block;
  width: 112px;
  height: auto;
}

.topbar h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.28rem, 2vw, 2rem);
  line-height: 1.08;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  justify-content: flex-end;
}

.icon-button,
.home-button {
  min-height: 48px;
  border: 2px solid #263d51;
  border-radius: 8px;
  background: #122436;
  color: #ffffff;
  font: inherit;
  font-weight: 800;
}

.icon-button {
  width: 48px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.icon-button .icon {
  display: block;
  width: 24px;
  height: 24px;
}

.home-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

.icon-button:hover,
.home-button:hover {
  border-color: #8fd8f3;
  background: var(--rrr-blue);
  color: #06111a;
}

.icon-button:focus-visible,
.home-button:focus-visible {
  outline: 4px solid rgba(143, 216, 243, 0.5);
  outline-offset: 2px;
}

#roundingRangeRescueModel,
.rrr-model,
.rrr-game {
  min-height: 0;
  height: 100%;
}

.rrr-game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  color: var(--rrr-ink);
  background:
    linear-gradient(#dce8f0 1px, transparent 1px),
    linear-gradient(90deg, #dce8f0 1px, transparent 1px),
    #eef4f8;
  background-size: 34px 34px;
}

.rrr-toolbar {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 14px;
  border-bottom: 1px solid var(--rrr-line);
  background: #ffffff;
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 2;
}

.rrr-set-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--rrr-muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.rrr-set-label select,
.rrr-button,
.rrr-boundary-inputs input {
  min-height: 48px;
  border: 2px solid var(--rrr-line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--rrr-ink);
  font: inherit;
  font-weight: 850;
}

.rrr-boundary-inputs input.is-correct {
  border-color: rgba(29, 143, 90, 0.72);
  background: #edfaf4;
}

.rrr-boundary-inputs input.is-wrong {
  border-color: rgba(216, 79, 79, 0.78);
  background: #fff7f7;
}

.rrr-boundary-status {
  min-height: 1.25em;
  display: block;
  color: var(--rrr-muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.rrr-boundary-status.is-correct {
  color: #145f3d;
}

.rrr-boundary-status.is-wrong {
  color: #982a2a;
}

.rrr-set-label select {
  padding: 0 34px 0 12px;
}

.rrr-button {
  padding: 0 14px;
  cursor: pointer;
}

.rrr-button:hover:not(:disabled) {
  border-color: #8fbfd8;
  background: #f4fbfe;
}

.rrr-button.rrr-primary {
  border-color: #4d409f;
  background: var(--rrr-violet);
  color: #ffffff;
}

.rrr-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.rrr-button:focus-visible,
.rrr-set-label select:focus-visible,
.rrr-boundary-inputs input:focus-visible,
.rrr-segmented input:focus-visible + span,
.rrr-related a:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.38);
  outline-offset: 2px;
}

.rrr-stage {
  width: min(1480px, calc(100% - 24px));
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(450px, 38%);
  gap: 12px;
  margin: 0 auto;
  padding: 10px 0;
  overflow: hidden;
}

.rrr-model-card,
.rrr-work-card {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--rrr-line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(15, 33, 49, 0.13);
}

.rrr-model-card {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto;
  align-content: start;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
}

.rrr-round {
  justify-self: start;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eaf6fb;
  color: #0b6e9a;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.rrr-model-card h2 {
  margin: 0;
  font-size: clamp(1.18rem, 2.1vw, 1.8rem);
  line-height: 1.16;
  text-align: center;
}

.rrr-model-host {
  width: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 480 / 166;
  display: grid;
  place-items: stretch;
  overflow: hidden;
  border: 2px solid #c8d9e5;
  border-radius: 8px;
  background: #fbfdff;
}

.rrr-model-host .spire-diagram,
.rrr-model-host figure,
.rrr-model-host svg {
  width: 100%;
  height: 100%;
  min-height: 150px;
  max-height: none;
}

.rrr-model-host figure {
  margin: 0;
}

.rrr-model-host figcaption {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.rrr-interval,
.rrr-support,
.rrr-feedback,
.rrr-related {
  margin: 0;
  border-radius: 8px;
  font-weight: 800;
  line-height: 1.3;
}

.rrr-interval {
  padding: 8px 10px;
  border: 1px solid #9fd2e8;
  background: #eef9fd;
  text-align: center;
}

.rrr-support {
  padding: 8px 10px;
  border: 1px solid #e5c06a;
  background: #fff9e8;
}

.rrr-feedback {
  min-height: 54px;
  display: grid;
  align-items: center;
  padding: 8px 12px;
  border: 2px solid var(--rrr-line);
  background: #f8fbfd;
}

.rrr-feedback[data-tone="success"] {
  border-color: rgba(29, 143, 90, 0.48);
  background: #edfaf4;
  color: #145f3d;
}

.rrr-feedback[data-tone="error"] {
  border-color: rgba(216, 79, 79, 0.48);
  background: #fff0f0;
  color: #982a2a;
}

.rrr-feedback[data-tone="support"] {
  border-color: rgba(243, 178, 58, 0.7);
  background: #fff9e8;
}

.rrr-related {
  text-align: center;
}

.rrr-related a {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  color: #075f87;
  font-weight: 900;
}

.rrr-work-card {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  overflow: auto;
}

.rrr-boundary-stage,
.rrr-candidate-stage {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 2px solid var(--rrr-line);
  border-radius: 8px;
}

.rrr-boundary-stage.is-complete {
  border-color: rgba(29, 143, 90, 0.5);
  background: #f4fbf7;
}

.rrr-boundary-stage > legend,
.rrr-candidate-stage > legend {
  padding: 0 6px;
  font-size: 1rem;
  font-weight: 900;
}

.rrr-boundary-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rrr-boundary-field {
  display: grid;
  gap: 6px;
}

.rrr-boundary-field > label {
  color: var(--rrr-muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.rrr-boundary-inputs input {
  width: 100%;
  padding: 0 10px;
  color: var(--rrr-ink);
  font-size: 1.12rem;
}

.rrr-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.rrr-candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.rrr-candidate-pair {
  min-width: 0;
  padding: 8px;
  border: 2px solid #c8d9e5;
  border-radius: 8px;
  background: #f8fbfd;
}

.rrr-candidate-pair > h3 {
  margin: 0 0 7px;
  color: #385264;
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.rrr-candidate-pair.is-correct {
  border-color: rgba(29, 143, 90, 0.52);
}

.rrr-candidate-pair.is-wrong {
  border-color: rgba(216, 79, 79, 0.62);
}

.rrr-pair-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.rrr-pair-feedback {
  margin: 7px 0 0;
  color: #982a2a;
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.25;
}

.rrr-candidate {
  min-width: 0;
  margin: 0;
  padding: 6px;
  border: 2px solid var(--rrr-line);
  border-radius: 8px;
  background: #fbfdff;
}

.rrr-candidate > legend {
  width: 100%;
  padding: 0 4px 4px;
  color: var(--rrr-ink);
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 900;
  text-align: center;
}

.rrr-candidate.is-correct {
  border-color: rgba(29, 143, 90, 0.62);
  background: #edfaf4;
}

.rrr-candidate.is-wrong {
  border-color: rgba(216, 79, 79, 0.68);
  background: #fff0f0;
}

.rrr-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.rrr-segmented label {
  position: relative;
  min-width: 0;
}

.rrr-segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.rrr-segmented span {
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid #b8cbd8;
  border-radius: 8px;
  background: #ffffff;
  font-weight: 900;
  cursor: pointer;
}

.rrr-segmented input:checked + span {
  border-color: var(--rrr-blue);
  background: #e7f6fc;
  color: #075f87;
}

.rrr-complete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 2px solid rgba(29, 143, 90, 0.5);
  border-radius: 8px;
  background: #edfaf4;
  color: #145f3d;
}

.rrr-complete p {
  margin: 4px 0 0;
  color: #145f3d;
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.25;
}

@media (min-width: 1200px) and (min-height: 650px) {
  .rrr-candidate-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rrr-pair-options {
    grid-template-columns: minmax(0, 1fr);
  }

  .rrr-candidate > legend {
    font-size: clamp(0.9rem, 1.1vw, 1rem);
  }
}

@media (max-width: 899px), (max-height: 649px) {
  body {
    overflow: auto;
  }

  .app,
  #roundingRangeRescueModel,
  .rrr-model,
  .rrr-game {
    height: auto;
    min-height: 100%;
  }

  .rrr-stage {
    width: min(100% - 20px, 760px);
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
  }

  .rrr-model-card,
  .rrr-work-card {
    overflow: visible;
  }

  .rrr-model-host {
    height: 170px;
    min-height: 170px;
    aspect-ratio: auto;
  }
}

@media (max-width: 520px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .top-actions {
    justify-content: flex-start;
  }

  .brand img {
    width: 88px;
  }

  .topbar h1 {
    white-space: normal;
  }

  .rrr-toolbar {
    justify-content: flex-start;
  }

  .rrr-set-label {
    width: 100%;
  }

  .rrr-set-label select {
    flex: 1;
    min-width: 0;
  }

  .rrr-boundary-inputs,
  .rrr-candidate-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .rrr-actions .rrr-button {
    flex: 1 1 132px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
