:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #152f28;
  background: #e6efea;
  --surface: #fbfdfb;
  --accent: #205d49;
  --muted: #4a655b;
  --line: #b6c8be;
  --heavy: #25493d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; }
h1, h2, p { margin: 0; }
button, input { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 3px solid #14694d; outline-offset: 3px; }

.top { border-bottom: 1px solid #c9d8d0; }
.top-content, main {
  width: min(100%, 34rem);
  margin-inline: auto;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
.top-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: calc(3.5rem + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: .55rem; font-size: .95rem; font-weight: 720; }
.brand img { border-radius: .55rem; }
main { padding-top: 1.65rem; padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
.game-heading, .game-meta { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.game-heading h1 { font-size: clamp(2.1rem, 8vw, 3rem); line-height: .98; letter-spacing: -.055em; }
#level { font-size: .92rem; color: var(--muted); margin-top: .5rem; }
.game-meta { color: var(--muted); min-height: 1.6rem; font-size: .85rem; margin-block: .9rem .35rem; }
#save-status { text-align: right; }

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 2px solid var(--heavy);
  border-radius: .6rem;
  overflow: hidden;
  background: var(--surface);
}
.cell {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-size: clamp(1.05rem, 6vw, 2rem);
  font-variant-numeric: tabular-nums;
  font-weight: 550;
  -webkit-tap-highlight-color: transparent;
}
.cell:nth-child(3n) { border-right: 2px solid var(--heavy); }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--heavy); }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.given { color: #142a23; font-weight: 760; }
.cell.related { background: #e8f2ed; }
.cell.same { background: #cfe7da; }
.cell.selected { background: #b7dcc9; box-shadow: inset 0 0 0 2px #37795f; }
.cell:focus-visible { outline-offset: -4px; }
.cell.invalid { color: #9e2734; text-decoration: underline; text-underline-offset: .15em; }
.cell-notes {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  font-size: clamp(.52rem, 2.45vw, .85rem);
  line-height: 1;
  color: #2f5f4e;
}
.actions, .digits, .levels { display: grid; gap: .38rem; }
.actions { grid-template-columns: repeat(3, 1fr); margin-top: .65rem; }
.digits { grid-template-columns: repeat(9, minmax(0, 1fr)); margin-top: .55rem; }
.actions button, .digits button, .outline, .primary, .quiet {
  border-radius: .58rem;
  border: 1px solid var(--line);
  min-height: 44px;
  background: var(--surface);
  color: #214638;
  font-weight: 680;
}
.actions button { font-size: .87rem; padding: 0 .15rem; }
.actions button[aria-pressed="true"] { border-color: #3d745d; background: #cfe8d9; }
.digits button { background: #f7fbf8; padding: 0; min-height: clamp(44px, 12vw, 57px); font-size: clamp(1.23rem, 5vw, 1.65rem); }
.outline, .primary, .quiet { padding: .55rem .85rem; }
.primary { display: inline-block; background: var(--accent); color: white; border-color: var(--accent); text-decoration: none; }
.quiet { background: transparent; border-color: transparent; }
.card, dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  color: inherit;
}
.login { margin: 7vh auto 0; max-width: 25rem; padding: clamp(1.2rem, 6vw, 2rem); }
.login h1 { font-size: 1.8rem; letter-spacing: -.035em; margin-bottom: 1.1rem; }
.login p { margin-bottom: 1rem; }
#login-form, label { display: grid; gap: .5rem; }
#login-form { gap: .9rem; }
label { font-weight: 630; }
input {
  width: 100%;
  min-height: 46px;
  padding: .6rem .7rem;
  border: 1px solid #879e92;
  border-radius: .55rem;
  color: inherit;
  background: white;
}
.message, .feedback { margin-top: .85rem; }
.message:empty { display: none; }
#retry { margin-top: .7rem; }
.feedback { padding: .7rem; }
#victory { font-weight: 750; text-align: center; color: var(--accent); }
dialog { width: min(calc(100% - 2rem), 25rem); padding: 0; }
dialog::backdrop { background: #142a2370; }
.dialog-content { padding: 1.2rem; }
.dialog-content p { margin-top: .5rem; color: var(--muted); }
.levels { margin-block: .9rem .4rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .65rem; }

@media (max-width: 390px) {
  main { padding-top: 1rem; }
  .digits { gap: .22rem; }
  .board { border-radius: .4rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .board { max-width: 23rem; margin-inline: auto; }
}
