:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --paper: #eef4f8;
  --line: #d8e2ea;
  --dark: #071018;
  --accent: #8b4b90;
  --accent-dark: #5a115a;
  --good: #a8f8a6;
  --bad: #ffaaa9;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.14);
  --radius: 8px;
  --touch: 48px;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  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;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
input,
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,
input:focus-visible,
select:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

input,
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 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#fourOperationsPuzzleModel {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: var(--dark);
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.brand-logo:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 3px;
}

.brand img {
  width: 142px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 2rem);
  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,
.icon-button[aria-pressed="true"] {
  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;
}

.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.toolbar {
  justify-content: center;
  flex-wrap: nowrap;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 3;
  scrollbar-width: thin;
}

.control-label,
.check-pill {
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.control-group {
  flex-wrap: nowrap;
}

.reveal-select {
  width: 64px;
  min-height: 40px;
  text-align: center;
}

.wide-button {
  min-height: 40px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--line);
  background: #f8fbfd;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.wide-button:hover {
  border-color: #9cc9df;
}

.wide-button.primary,
.wide-button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #ffffff;
}

.check-pill {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  white-space: nowrap;
}

.check-pill input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.workspace {
  min-height: 0;
  overflow: hidden;
  padding: 10px;
}

.tool-surface {
  width: min(1180px, calc(100vw - 20px));
  height: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.puzzle-intro {
  margin: 0 0 6px;
  color: var(--muted);
  text-align: center;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 800;
}

.digits-left {
  min-height: 0;
  margin-bottom: 8px;
  color: var(--accent-dark);
  text-align: center;
  font-size: clamp(1.5rem, 4vw, 2.6rem);
  font-weight: 900;
  line-height: 1.15;
}

.board-wrap {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: start center;
  padding: 12px;
  border: 2px solid #d7e5ec;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 22px 22px, rgba(20, 155, 215, 0.13) 2px, transparent 2px),
    linear-gradient(#fbfdff, #f3f8fb);
  background-size: 44px 44px, auto;
}

.ops-board {
  --tile-size: 86px;
  --result-width: 128px;
  --result-height: 78px;
  --gap: 6px;
  --zoom: 1;
  display: grid;
  grid-template-columns: repeat(5, calc(var(--tile-size) * var(--zoom))) calc(var(--result-width) * var(--zoom));
  grid-template-rows: repeat(5, calc(var(--tile-size) * var(--zoom))) calc(var(--result-height) * var(--zoom));
  gap: calc(var(--gap) * var(--zoom));
}

.tile,
.result-tile {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 2px solid #e3ecf1;
  border-radius: var(--radius);
  background: #ffffff;
  color: #05070d;
  box-shadow: 6px 7px 0 rgba(90, 17, 90, 0.14);
  font-size: clamp(1rem, calc(2.55rem * var(--zoom)), 2.55rem);
  font-weight: 900;
}

.result-tile {
  background: var(--good);
  font-size: clamp(0.8rem, calc(1.85rem * var(--zoom)), 1.85rem);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.column-result {
  font-size: clamp(0.72rem, calc(1.35rem * var(--zoom)), 1.35rem);
}

.result-tile.pending {
  background: #eef6fb;
  color: var(--muted);
}

.result-tile.wrong {
  background: var(--bad);
}

.operator-tile {
  color: #05070d;
  font-size: clamp(1rem, calc(2.45rem * var(--zoom)), 2.45rem);
}

.digit-tile.revealed {
  background: #ffffff;
}

.digit-input {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: var(--radius);
  color: #05070d;
  background: #ffffff;
  font-size: clamp(1rem, calc(2.55rem * var(--zoom)), 2.55rem);
  font-weight: 900;
  text-align: center;
}

.digit-input:disabled {
  color: #05070d;
  opacity: 1;
}

.digit-input.duplicate {
  background: #fff6cf;
}

.blank-tile {
  visibility: hidden;
}

.feedback {
  min-height: 56px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  font-weight: 800;
  line-height: 1.3;
}

.feedback.good {
  border-color: #76b947;
  background: #eef9e8;
  color: #22510f;
}

.feedback.try {
  border-color: #f2b84b;
  background: #fff8e6;
  color: #6a4300;
}

.print-logo,
.print-copyright {
  display: none;
}

.instructions-dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: min(800px, calc(100vh - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(6, 17, 26, 0.32);
}

.instructions-dialog::backdrop {
  background: rgba(6, 17, 26, 0.5);
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--dark);
  color: #ffffff;
}

.instructions-header h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.15;
}

.instructions-body {
  max-height: calc(min(800px, 100vh - 32px) - 76px);
  overflow: auto;
  padding: 16px 18px 20px;
  line-height: 1.45;
}

.instructions-body h3 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.instructions-body h3:first-child {
  margin-top: 0;
}

.instructions-body p,
.instructions-body ul {
  margin: 0 0 10px;
}

.instructions-body li {
  margin-bottom: 6px;
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: start;
  }

  .toolbar {
    justify-content: start;
  }

  .digits-left {
    text-align: left;
  }

  .tool-surface {
    padding: 10px;
  }
}

@media print {
  @page {
    size: landscape;
  }

  body {
    background: #ffffff;
  }

  .topbar,
  .toolbar,
  .feedback,
  .instructions-dialog {
    display: none;
  }

  .workspace {
    overflow: visible;
    padding: 0;
  }

  .tool-surface,
  .board-wrap {
    width: 100%;
    min-height: 0;
    box-shadow: none;
    border: 1px solid #000000;
    background: #ffffff;
  }

  .ops-board {
    transform: none !important;
    margin: 0 auto;
  }

  .print-logo {
    display: block;
    width: 150px;
    margin-bottom: 10px;
  }

  .print-copyright {
    display: block;
    margin-top: 10px;
    color: #000000;
    font-size: 11pt;
    font-weight: 700;
    text-align: right;
  }
}
