:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #666;
  --line: #d9d9d9;
  --surface: #f7f7f7;
  --error: #a32929;
  --success: #315c3b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #fff; }
a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid #777; outline-offset: 3px; }

.site-shell { width: min(100% - 2rem, 980px); margin: 0 auto; }
.site-header { padding: 1.25rem 0 2rem; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: -.02em; text-decoration: none; }
.page-main { padding: 2.5rem 0 4rem; }
.page-main > h1 { margin-left: auto; margin-right: auto; font-size: clamp(1rem, 3.6vw, 2rem); text-align: center; }
.page-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem 1.5rem; padding: 1.5rem 0 2.5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.page-footer a:hover, .back-link:hover { color: var(--ink); }
.back-link { display: inline-block; margin-bottom: 2rem; color: var(--muted); font-size: .9rem; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 760px; font-size: clamp(2.15rem, 4vw, 3.2rem); line-height: 1.05; letter-spacing: -.045em; }
h2 { margin-bottom: .75rem; font-size: 1.45rem; letter-spacing: -.02em; }
h3 { margin-bottom: .4rem; font-size: 1.05rem; }
.muted { color: var(--muted); }
.intro { max-width: 640px; font-size: 1.08rem; color: var(--muted); }
.principles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem 1.2rem; margin: 2rem 0 3rem; color: var(--muted); }
.principles p { margin: 0; padding: .8rem .7rem; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.activity-grid { display: grid; gap: .8rem; }
.activity-card { display: block; min-height: 145px; padding: 1.25rem; border: 1px solid var(--line); text-decoration: none; transition: border-color .15s ease, background .15s ease; }
.activity-card:hover { border-color: #777; background: var(--surface); }
.activity-card p { margin-bottom: 0; color: var(--muted); }
.activity-icon { display: block; margin-bottom: 1rem; color: var(--muted); }
.activity-layout { max-width: 720px; margin: 0 auto; }
.about-page { max-width: 760px; }
.about-copy { max-width: 660px; margin: 2rem auto 0; }
.about-copy p { margin-bottom: 1.4rem; color: var(--muted); }
.activity-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.activity-top .back-link { margin-bottom: 0; }
.activity-description { display: flex; max-width: 520px; margin: 0; align-items: flex-start; justify-content: flex-end; gap: .35rem; color: var(--muted); text-align: right; }
.activity-description > span { min-width: 0; }
.activity-title { margin: 0 auto 1.5rem; font-size: clamp(1.65rem, 5vw, 2.35rem); text-align: center; }
.activity-header { margin-bottom: 1.5rem; }
.activity-header h1 { font-size: clamp(1.65rem, 5vw, 2.35rem); }
.activity-layout > .intro { margin-left: auto; margin-right: auto; text-align: center; }
.panel { padding: 1.25rem; border: 1px solid var(--line); }
.sudoku-panel { border-color: #777; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: .65rem; align-items: center; margin-bottom: 1.25rem; }
label { display: grid; gap: .3rem; color: var(--muted); font-size: .9rem; }
select, input[type="text"], input[type="number"] { min-height: 2.7rem; padding: .55rem .7rem; border: 1px solid #aaa; border-radius: 0; background: #fff; color: var(--ink); }
button, .button { min-height: 2.7rem; padding: .55rem .9rem; border: 1px solid var(--ink); border-radius: 0; background: var(--ink); color: #fff; text-decoration: none; }
button.secondary, .button.secondary { background: #fff; color: var(--ink); border-color: #aaa; }
@media (hover: hover) {
  button:hover, .button:hover { opacity: .8; }
}
.status { min-height: 1.6rem; margin: 1rem 0 0; color: var(--muted); text-align: center; }
.panel .status + .controls, .panel .status + button { margin-top: 1.25rem; }
.panel > button { display: block; margin-left: auto; margin-right: auto; }
.status.error { color: var(--error); }
.status.success { color: var(--success); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Sudoku */
.sudoku-grid { position: relative; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); width: 100%; max-width: 560px; min-width: 0; margin: 1.5rem auto; overflow: hidden; border: 2px solid #555; }
.sudoku-grid::before, .sudoku-grid::after { position: absolute; z-index: 2; display: block; pointer-events: none; content: ''; }
.sudoku-grid::before { inset: 0; background: linear-gradient(to right, transparent calc(33.333% - 1px), #555 calc(33.333% - 1px), #555 calc(33.333% + 1px), transparent calc(33.333% + 1px), transparent calc(66.666% - 1px), #555 calc(66.666% - 1px), #555 calc(66.666% + 1px), transparent calc(66.666% + 1px)); }
.sudoku-grid::after { inset: 0; background: linear-gradient(to bottom, transparent calc(33.333% - 1px), #555 calc(33.333% - 1px), #555 calc(33.333% + 1px), transparent calc(33.333% + 1px), transparent calc(66.666% - 1px), #555 calc(66.666% - 1px), #555 calc(66.666% + 1px), transparent calc(66.666% + 1px)); }
.sudoku-cell { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 100%; aspect-ratio: 1; min-width: 0; min-height: 0; padding: 0 !important; border: 0; border-right: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8; border-radius: 0; background: #fff; color: var(--ink); font-family: inherit; font-size: clamp(1rem, 5vw, 1.6rem); line-height: 1; text-align: center !important; text-indent: 0; }
.sudoku-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid #555; }
.sudoku-cell:nth-child(9n) { border-right: 0; }
.sudoku-cell:nth-child(n+19):nth-child(-n+27), .sudoku-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid #555; }
.sudoku-cell:nth-child(n+73) { border-bottom: 0; }
.sudoku-cell.given { background: var(--surface); font-weight: 700; }
.sudoku-cell.selected { box-shadow: inset 0 0 0 3px #777; }
.sudoku-cell.wrong { color: var(--error); background: #fff1f1; }
.sudoku-cell.conflict { color: var(--error); background: #fff1f1; }
.sudoku-keypad { display: grid; grid-template-columns: repeat(5, minmax(2.7rem, 3.5rem)); justify-content: center; gap: .5rem; margin: 1rem auto; }
.sudoku-keypad button { min-height: 2.7rem; }

/* Wordle */
.word-grid { display: grid; grid-template-columns: repeat(5, minmax(2.9rem, 3.6rem)); gap: .4rem; justify-content: center; margin: 1.5rem 0; }
.word-tile { width: 100%; aspect-ratio: 1; padding: 0; border: 2px solid #d3d6da; border-radius: 0; background: #fff; font-size: 1.5rem; font-weight: 700; text-align: center; text-transform: uppercase; }
.word-tile.filled { border-color: var(--ink); }
.word-tile.correct { background: #6aaa64; color: #fff; border-color: #6aaa64; }
.word-tile.present { background: #c9b458; color: #fff; border-color: #c9b458; }
.word-tile.absent { background: #eee; color: #777; border-color: #ddd; }
.word-keyboard { display: grid; gap: .4rem; max-width: 430px; margin: 1rem auto; }
.keyboard-row { display: flex; width: 100%; justify-content: center; gap: .3rem; }
.keyboard-key { min-width: 1.9rem; min-height: 2.7rem; padding: .4rem; border: 1px solid #aaa; border-radius: 4px; background: #eee; color: var(--ink); font-size: .8rem; font-weight: 700; }
.keyboard-key.wide { min-width: 3.5rem; }
.keyboard-key.correct { background: #6aaa64; border-color: #6aaa64; color: #fff; }
.keyboard-key.present { background: #c9b458; border-color: #c9b458; color: #fff; }
.keyboard-key.absent { background: #777; border-color: #777; color: #fff; }

/* Pattern */
.pattern-grid { display: grid; gap: .35rem; width: min(100%, 360px); margin: 1.5rem auto; }
.pattern-cell { aspect-ratio: 1; border: 1px solid #aaa; background: #fff; }
.pattern-cell.active, .pattern-cell.selected { background: var(--ink); border-color: var(--ink); }
.pattern-cell.incorrect { background: #f5dede; border-color: var(--error); }

.article-card { min-height: 230px; }
.definition-word { margin-bottom: .25rem; font-size: clamp(2rem, 8vw, 3.4rem); letter-spacing: -.04em; }
.definition-type { color: var(--muted); font-style: italic; }
.math-problem { margin: 2rem 0; font-size: clamp(2rem, 12vw, 5rem); letter-spacing: .03em; text-align: center; }
.math-answer { width: min(100%, 15rem); margin: 0 auto; }
.math-answer input { width: 100%; text-align: center; font-size: 1.5rem; }
.math-keypad { display: grid; grid-template-columns: repeat(3, minmax(3rem, 4rem)); justify-content: center; gap: .5rem; margin: 1rem auto; }

@media (min-width: 680px) {
  .site-shell { width: min(100% - 4rem, 1080px); }
  .site-header { padding-top: 2rem; }
  .principles { grid-template-columns: repeat(4, 1fr); }
  .activity-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .panel { padding: 2rem; }
}

/* Information dialogs */
.info-button { display: inline-grid; width: 1.35rem; height: 1.35rem; margin-left: .35rem; padding: 0; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--muted); vertical-align: -.12rem; }
.info-button svg { width: 1.15rem; height: 1.15rem; }
.info-button:hover { color: var(--ink); border-color: var(--ink); }
dialog.info-dialog { width: min(calc(100% - 2rem), 30rem); max-width: 30rem; padding: 0; border: 1px solid #777; background: #fff; color: var(--ink); }
dialog.info-dialog::backdrop { background: rgb(0 0 0 / .28); }
.info-dialog-content { padding: 1.5rem; }
.info-dialog h2 { margin-bottom: 1rem; font-size: 1.25rem; }
.info-dialog p { color: var(--muted); }
.info-dialog ul { margin: 0 0 1.25rem; padding-left: 1.2rem; color: var(--muted); }
.info-dialog li + li { margin-top: .55rem; }
.info-dialog-close { display: block; margin-left: auto; }

/* Resource pages */
.resource-page { max-width: 760px; }
.resource-page > h1 { margin-bottom: 1rem; text-align: center; }
.resource-lead { max-width: 650px; margin: 0 auto 2.5rem; color: var(--muted); text-align: center; }
.resource-list { display: grid; gap: .8rem; margin: 0; padding: 0; list-style: none; }
.resource-list a { display: block; padding: 1rem; border: 1px solid var(--line); text-decoration: none; }
.resource-list a:hover { border-color: #777; background: var(--surface); }
.resource-list p { margin: .35rem 0 0; color: var(--muted); }
.resource-copy { max-width: 680px; margin: 2rem auto 0; }
.resource-copy h2 { margin-top: 2rem; }
.resource-copy p, .resource-copy li { color: var(--muted); }
.resource-copy ul { padding-left: 1.25rem; }
.resource-copy li + li { margin-top: .55rem; }
.resource-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem; margin-top: 2rem; }

@media (max-width: 460px) {
  .activity-top { flex-direction: column; align-items: stretch; }
  .activity-description { max-width: none; justify-content: flex-start; text-align: left; }
  .activity-title { font-size: 1.55rem; }
  .keyboard-key { min-width: 0; flex: 1 1 0; padding-left: .2rem; padding-right: .2rem; }
  .keyboard-key.wide { min-width: 0; flex: 1.5 1 0; }
  .info-dialog-content { padding: 1.25rem; }
}
