:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --paper: #eef4f8;
  --panel: #ffffff;
  --line: #d8e2ea;
  --dark: #071018;
  --green: #1d8f5a;
  --amber: #f3b23a;
  --red: #d84f4f;
  --violet: #6d5fd0;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.14);
  --radius: 8px;
  --touch: 48px;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(#dce8f0 1px, transparent 1px),
    linear-gradient(90deg, #dce8f0 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
select { font: inherit; }

button {
  min-height: var(--touch);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

select {
  min-height: var(--touch);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: var(--dark);
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.brand img {
  width: 112px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.05rem);
  line-height: 1.05;
  font-weight: 800;
}

.top-actions,
.toolbar,
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions { justify-content: end; }

.icon-button {
  width: var(--touch);
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #122436;
  color: #ffffff;
  border-color: #263d51;
}

.icon-button:hover,
.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.home-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid #263d51;
  border-radius: var(--radius);
  background: #122436;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.toolbar {
  justify-content: center;
  padding: 6px 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 3;
}

.control-label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.wide-button {
  min-height: var(--touch);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  background: #f8fbfd;
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
}

.wide-button.primary {
  background: var(--violet);
  border-color: #4d409f;
  color: #ffffff;
}

.game-shell {
  width: min(1160px, calc(100% - 24px));
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 8px 0;
  overflow: hidden;
}

.game-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 10px;
  overflow: hidden;
}

.game-board,
.instructions-panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.game-board {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fbfdff;
}

.stat {
  display: grid;
  gap: 3px;
  padding: 7px 10px;
  border-right: 1px solid var(--line);
  justify-items: center;
  text-align: center;
}

.stat:last-child { border-right: 0; }

.stat span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  font-size: clamp(1.15rem, 2vw, 1.65rem);
  line-height: 1;
}

.play-area {
  min-height: 0;
  display: grid;
  place-items: center;
  border: 2px solid #c8d9e5;
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.prompt {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  font-size: clamp(0.98rem, 1.75vw, 1.3rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.25;
}

.prompt.good {
  border-color: rgba(29, 143, 90, 0.42);
  background: #edfaf4;
  color: #145f3d;
}

.prompt.bad {
  border-color: rgba(216, 79, 79, 0.42);
  background: #fff0f0;
  color: #9d2828;
}

.instructions-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.instructions-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.instruction-toggle {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border-color: #c8d9e5;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
  text-align: left;
}

.instruction-toggle:hover {
  border-color: #8fbfd8;
  background: #f4fbfe;
}

.instruction-toggle::after {
  content: "+";
  float: right;
  font-size: 1.15rem;
  line-height: 1;
}

.instruction-toggle[aria-expanded="true"]::after {
  content: "-";
}

.instructions-panel p,
.instructions-panel li {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.28;
}

.instructions-panel ol {
  margin: 0;
  padding-left: 20px;
}

.instructions-panel li + li { margin-top: 5px; }

.instructions-panel.instructions-collapsed > p,
.instructions-panel.instructions-collapsed > ol {
  display: none;
}

.mode-card {
  padding: 9px 10px;
  border: 1px solid #c8d9e5;
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.25;
}

.team-panel {
  display: grid;
  gap: 7px;
}

.team-panel h3 {
  margin: 0;
  font-size: 0.92rem;
}

.team-scores {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.team-score {
  display: grid;
  gap: 2px;
  min-height: 50px;
  align-content: center;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.team-score.active {
  border-color: var(--violet);
  background: #f2f0ff;
}

.team-score span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.team-score strong {
  color: var(--ink);
  font-size: 1.32rem;
  line-height: 1;
}

@media (max-width: 760px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .game-info-panel {
    grid-row: 1;
    padding: 8px;
  }

  .game-board {
    grid-row: 2;
  }

  .team-panel {
    max-height: 112px;
    overflow: auto;
  }
}

/* Shared variants for a single full-width mathematical workspace. */
.game-shell--wide { width: min(1400px, calc(100% - 24px)); }
.game-layout--single { grid-template-columns: minmax(0, 1fr); }
.game-board--with-actions { grid-template-rows: auto minmax(0, 1fr) auto auto; }
.play-area--workspace { display: block; place-items: stretch; }
.status-strip--compact .stat { padding: 4px 10px; }
.status-strip--compact .stat span { font-size: 0.72rem; }
.status-strip--compact .stat strong { font-size: clamp(1.15rem, 1.6vw, 1.45rem); }
.game-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
button:disabled { cursor: default; opacity: 0.48; }
a:focus-visible, input:focus-visible { outline: 4px solid rgba(20, 155, 215, 0.35); outline-offset: 2px; }

@media (max-width: 850px), (max-height: 600px) {
  html:has(.app--scroll-narrow), body:has(.app--scroll-narrow) { height: auto; overflow: auto; }
  .app--scroll-narrow { height: auto; min-height: 100dvh; overflow: visible; }
  .app--scroll-narrow .topbar { grid-template-columns: minmax(0, 1fr); }
  .app--scroll-narrow .brand { flex-wrap: wrap; }
  .app--scroll-narrow .top-actions { justify-content: start; }
  .app--scroll-narrow .toolbar { justify-content: start; }
  .app--scroll-narrow .game-shell { height: auto; overflow: visible; }
  .app--scroll-narrow .game-layout { display: flex; flex-direction: column; height: auto; overflow: visible; }
  .app--scroll-narrow .game-board { display: flex; flex-direction: column; overflow: visible; }
  .app--scroll-narrow .play-area { overflow: visible; }
  .app--scroll-narrow .game-actions { justify-content: start; }
}
