* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
  background: #f6efe3;
  color: #2b2118;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
  display: flex;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}
.game {
  width: min(100%, 1040px);
  display: grid;
  grid-template-areas:
    "title"
    "board"
    "panel";
  gap: 14px;
}
.titlebar {
  grid-area: title;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}
.titlebar h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1;
}
.titlebar p {
  margin: 6px 0 0;
  color: #776b5e;
}
.tools {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.pill,
button {
  border: 2px solid #2b2118;
  border-radius: 10px;
  background: #fffaf0;
  color: #2b2118;
  font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 38px;
  padding: 8px 11px;
}
.pill {
  display: inline-grid;
  place-items: center;
  background: #efe0c3;
}
button {
  cursor: pointer;
}
button:focus-visible,
canvas:focus-visible {
  outline: 3px solid #0b7285;
  outline-offset: 2px;
}
button[aria-pressed="true"] {
  background: #0b7285;
  color: #fff;
}
.board-panel {
  grid-area: board;
  display: grid;
  justify-items: center;
  align-items: start;
}
.board-frame {
  width: min(100%, 500px);
  aspect-ratio: 1;
  border: 3px solid #2b2118;
  border-radius: 12px;
  overflow: hidden;
  background: #fffaf0;
  box-shadow: 0 8px 24px rgba(43, 33, 24, 0.12);
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  background: #fffaf0;
}
.control-panel {
  grid-area: panel;
  display: grid;
  gap: 10px;
  justify-items: center;
}
.controls {
  width: min(100%, 500px);
  display: grid;
  gap: 8px;
}
.digits {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
}
.digits button {
  min-width: 0;
  padding: 8px 0;
  font-size: 16px;
}
.functions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.status {
  width: min(100%, 500px);
  margin: 0;
  min-height: 24px;
  text-align: center;
  color: #62574c;
  font: 600 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
footer {
  width: min(100%, 500px);
  text-align: center;
  color: #776b5e;
  font-size: 12px;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 33, 24, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
}
.overlay[hidden] {
  display: none;
}
.dialog {
  width: min(100%, 360px);
  background: #fffaf0;
  border: 3px solid #2b2118;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(43, 33, 24, 0.24);
  text-align: center;
}
.dialog h2 {
  margin: 0 0 8px;
  font-size: 28px;
}
.dialog p {
  margin: 0 0 16px;
  color: #62574c;
}
.overlay-actions {
  display: grid;
  gap: 8px;
}
.overlay-actions button {
  width: 100%;
  font-size: 15px;
}
@media (min-width: 960px) and (min-height: 560px) {
  body {
    align-items: center;
  }
  .game {
    grid-template-columns: minmax(460px, 540px) minmax(280px, 320px);
    grid-template-areas:
      "board title"
      "board panel";
    justify-content: center;
    column-gap: clamp(28px, 4vw, 44px);
    row-gap: 18px;
  }
  .titlebar {
    display: grid;
    align-content: end;
    gap: 14px;
    padding-top: 4px;
  }
  .titlebar h1 {
    font-size: clamp(28px, 3vw, 34px);
  }
  .titlebar p {
    font-size: 14px;
  }
  .tools {
    justify-content: flex-start;
  }
  .board-panel {
    grid-row: 1 / span 2;
    align-self: center;
  }
  .board-frame {
    width: 100%;
    max-width: 540px;
  }
  .control-panel {
    align-self: start;
    justify-items: stretch;
    gap: 12px;
  }
  .controls,
  .status,
  footer {
    width: 100%;
  }
  .digits {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .digits button {
    min-height: 48px;
    font-size: 18px;
  }
  .functions {
    gap: 8px;
  }
  .functions button {
    min-height: 42px;
    padding-inline: 4px;
  }
  .status,
  footer {
    text-align: left;
  }
}
@media (max-width: 640px) and (orientation: portrait) {
  body {
    padding: max(8px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }
  .game {
    gap: 8px;
  }
  .titlebar {
    align-items: stretch;
  }
  .titlebar h1 {
    font-size: 30px;
  }
  .titlebar p {
    margin-top: 4px;
    font-size: 12px;
  }
  .tools {
    max-width: 48%;
    gap: 5px;
  }
  .tools button,
  .pill {
    min-height: 34px;
    padding: 6px 8px;
    font-size: 11px;
  }
  .board-frame {
    width: min(100%, 350px);
  }
  .control-panel {
    gap: 6px;
  }
  .controls {
    width: min(100%, 350px);
    gap: 5px;
  }
  .digits {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .digits button {
    min-height: 42px;
    padding: 5px 0;
  }
  .functions {
    gap: 5px;
  }
  .functions button {
    min-height: 38px;
    padding: 5px 3px;
    font-size: 11px;
  }
  .status {
    width: min(100%, 350px);
    min-height: 20px;
    font-size: 12px;
  }
  footer {
    display: none;
  }
}
@media (max-height: 600px) and (orientation: landscape) {
  body {
    align-items: center;
    padding: 6px;
  }
  .game {
    grid-template-columns: minmax(210px, 68vh) minmax(300px, 1fr);
    grid-template-areas:
      "board title"
      "board panel";
    width: min(100%, 900px);
    gap: 8px 14px;
  }
  .titlebar {
    grid-area: title;
  }
  .titlebar h1 {
    font-size: 26px;
  }
  .titlebar p {
    display: none;
  }
  .board-panel {
    grid-row: 1 / span 2;
    align-self: center;
  }
  .board-frame {
    width: min(68vh, 420px);
  }
  .control-panel {
    align-self: start;
    justify-items: stretch;
    gap: 6px;
  }
  .controls,
  .status {
    width: 100%;
  }
  .digits {
    grid-template-columns: repeat(9, 1fr);
    gap: 3px;
  }
  .digits button,
  .functions button {
    min-height: 34px;
  }
  .status {
    text-align: left;
  }
  footer {
    display: none;
  }
}
