/* Margin Guard (SAT tower defense). Black and white, shares Graphite's buttons and question styles. */

body.mode-guard .toolbar,
body.mode-guard .main,
body.mode-guard .header-right {
  display: none;
}

.m-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- HUD ---------- */

.m-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.m-hud.hidden {
  display: none;
}

.m-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1.5px solid var(--text);
  border-radius: 8px;
  background: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.m-chip.hidden {
  display: none;
}

.m-chip b {
  font-size: 1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.m-chip-wave {
  background: var(--text);
  color: #fff;
}

.m-chip-wave span {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.m-unit {
  font-size: 0.74rem;
  color: var(--muted);
}

.m-chip-shield {
  border-style: dashed;
}

.m-ink-ico,
.m-sheet-ico,
.m-shield-ico {
  display: inline-block;
  flex: none;
}

.m-ink-ico {
  width: 11px;
  height: 14px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--text);
  clip-path: polygon(50% 0, 100% 62%, 85% 92%, 50% 100%, 15% 92%, 0 62%);
}

.m-sheet-ico {
  width: 12px;
  height: 12px;
  border: 2px solid var(--text);
  border-radius: 50%;
  background: radial-gradient(circle, var(--text) 0 45%, transparent 46%);
}

.m-shield-ico {
  width: 13px;
  height: 14px;
  border: 2px dashed var(--text);
  border-radius: 6px 6px 8px 8px;
}

.m-hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.m-start kbd,
.m-tool kbd,
.m-pick kbd,
.m-pop-build kbd {
  padding: 0 4px;
  font: inherit;
  font-size: 0.66rem;
  font-weight: 700;
  border: 1px solid currentColor;
  border-radius: 3px;
  opacity: 0.75;
}

.m-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font: inherit;
  font-weight: 800;
  border: 1.5px solid var(--text);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.m-icon:hover {
  background: var(--text);
  color: #fff;
}

/* ---------- layout ---------- */

.m-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.m-board {
  flex: 1 1 62%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1.5px solid var(--text);
  border-radius: 8px;
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
}

.m-stage.is-portrait {
  aspect-ratio: 9 / 16;
  width: min(100%, calc(76vh * 9 / 16));
  margin: 0 auto;
}

.m-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: manipulation;
}

.m-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
}

.m-screen.hidden {
  display: none;
}

/* ---------- title & cards ---------- */

.m-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 520px;
  padding: 18px 22px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  text-align: center;
}

.m-logo {
  font-size: clamp(2.4rem, 7vw, 4.6rem);
  font-weight: 900;
  line-height: 0.88;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}

.m-logo::after {
  content: "";
  display: block;
  width: 64%;
  height: 6px;
  margin: 12px auto 0;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, var(--text) 0 14px, transparent 14px 20px);
}

.m-title .g-tagline {
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.m-new {
  min-width: 200px;
  padding: 12px 22px;
  font-size: 1rem;
}

.m-title-foot {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.m-card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 20px;
  border: 2px solid var(--text);
  border-radius: 10px;
  background: #fff;
  box-shadow: 4px 4px 0 var(--text);
  text-align: center;
}

.m-card-title {
  margin: 2px 0 8px;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1.15;
}

.m-card-sub {
  font-size: 0.85rem;
  color: #444;
}

.m-card .g-results-grid {
  grid-template-columns: repeat(2, 1fr);
}

.m-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- tower palette ---------- */

.m-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.m-palette.hidden {
  display: none;
}

.m-tool {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 6px 10px 6px 6px;
  font: inherit;
  text-align: left;
  border: 1.5px solid var(--text);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.m-tool canvas {
  grid-row: 1 / span 2;
  width: 44px;
  height: 44px;
}

.m-tool-name {
  font-size: 0.85rem;
  font-weight: 800;
}

.m-tool-cost {
  font-size: 0.75rem;
  color: var(--muted);
}

.m-tool:hover {
  background: #f6f6f6;
}

.m-tool.on {
  background: #efefef;
  box-shadow: inset 0 0 0 2px var(--text), 3px 3px 0 var(--text);
}

.m-tool.is-poor {
  opacity: 0.45;
}

.m-help {
  font-size: 0.78rem;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
}

.m-help b {
  color: var(--text);
}

/* ---------- build / upgrade popover ---------- */

.m-pop {
  position: absolute;
  z-index: 5;
  width: 230px;
  padding: 10px 12px 12px;
  border: 2px solid var(--text);
  border-radius: 10px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--text);
}

.m-pop.hidden {
  display: none;
}

.m-pop-title {
  margin-right: 24px;
  font-size: 0.95rem;
  font-weight: 900;
}

.m-pop-title span {
  margin-left: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.m-pop-stats,
.m-pop-note {
  margin: 4px 0 8px;
  font-size: 0.76rem;
  color: var(--muted);
}

.m-pop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.m-pop-build {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  border: 1.5px solid var(--text);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.m-pop-build span {
  font-size: 0.74rem;
  color: var(--muted);
  text-align: right;
}

.m-pop-build:hover:not(:disabled) {
  background: var(--text);
  color: #fff;
}

.m-pop-build:hover:not(:disabled) span {
  color: #ddd;
}

.m-pop-build:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.m-pop-build.is-sell {
  border-style: dashed;
}

.m-pop-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  border: 1px solid var(--border-dark, #bdbdbd);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.m-toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 6;
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
}

.m-toast.show {
  animation: m-toast 2.2s ease forwards;
}

@keyframes m-toast {
  10%,
  80% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
}

/* ---------- study hall (questions) ---------- */

.m-side {
  flex: 0 0 36%;
  max-width: 520px;
  max-height: min(78vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 14px;
  border: 1.5px solid var(--text);
  border-radius: 8px;
  background: #fff;
}

.m-side.hidden {
  display: none;
}

.m-side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.m-side-title {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.m-side-title b {
  font-size: 1rem;
  font-weight: 900;
}

.m-side-timer {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.m-side-toggle {
  display: none;
}

.m-link {
  padding: 4px 8px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid var(--text);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.m-q-picks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.m-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px 8px;
  font: inherit;
  border: 2px solid var(--text);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  box-shadow: 3px 3px 0 var(--text);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.m-pick b {
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.m-pick small {
  font-size: 0.7rem;
  color: var(--muted);
}

.m-pick:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--text);
}

.m-pick:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--text);
}

.m-pick:disabled {
  opacity: 0.3;
  box-shadow: none;
  cursor: not-allowed;
}

.m-q-lead {
  margin: 10px 0 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #333;
}

.m-q-tally {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

.m-q-next {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-dark, #bdbdbd);
}

.m-q-next .m-q-lead {
  margin-top: 0;
}

.m-q-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 8px;
  font-size: 0.9rem;
  text-align: center;
  color: var(--muted);
}

.m-paused .m-q-area {
  filter: blur(7px);
  pointer-events: none;
  user-select: none;
}

/* shared question card (qcard.js) */

.qc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.qc-head h3 {
  font-size: 1.1rem;
  font-weight: 900;
}

.qc-skill {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  margin: 4px 0 10px;
  padding-bottom: 8px;
  font-size: 0.76rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.qc-timer {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.qc-timer.is-late {
  color: var(--muted);
}

.qc-body .viewer-stimulus,
.qc-body .viewer-stem {
  margin-bottom: 10px;
}

.qc-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.qc-actions .qc-lock {
  min-width: 130px;
}

/* ---------- phones: the study hall becomes a drawer ---------- */

@media (max-width: 719px) {
  .m-main {
    flex-direction: column;
    align-items: stretch;
  }

  .m-hud {
    gap: 5px;
  }

  .m-chip {
    padding: 4px 7px;
    font-size: 0.75rem;
  }

  .m-unit {
    display: none;
  }

  .m-hud-actions {
    width: 100%;
    margin-left: 0;
  }

  .m-hud-actions .m-start {
    flex: 1;
  }

  .m-palette {
    gap: 5px;
  }

  .m-tool {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 4px;
    text-align: center;
  }

  .m-tool canvas {
    grid-row: auto;
    width: 34px;
    height: 34px;
  }

  .m-tool-name {
    font-size: 0.7rem;
  }

  .m-tool-name kbd,
  .m-help,
  .m-pick kbd {
    display: none;
  }

  /* the board fits above the study drawer's peek */
  .m-stage.is-portrait {
    width: min(100%, calc((100vh - 335px) * 9 / 16));
    width: min(100%, calc((100svh - 335px) * 9 / 16));
  }

  .m-side {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 800;
    max-width: none;
    max-height: 74vh;
    padding-top: 6px;
    border: 2px solid var(--text);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.14);
    transform: translateY(calc(100% - 150px));
    transition: transform 0.25s ease;
  }

  .m-side.is-open {
    transform: none;
  }

  .m-side-toggle {
    display: block;
    position: absolute;
    top: 0;
    left: 50%;
    width: 64px;
    height: 18px;
    padding: 0;
    border: 0;
    background: transparent;
    transform: translateX(-50%);
    cursor: pointer;
  }

  .m-side-toggle span {
    display: block;
    width: 40px;
    height: 4px;
    margin: 7px auto 0;
    border-radius: 2px;
    background: var(--text);
  }

  .m-side-head {
    padding-top: 8px;
  }

  body.mode-guard .app {
    padding-bottom: 170px;
  }

  .m-pop {
    width: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .m-side,
  .m-pick {
    transition: none;
  }
}
