/* Clear Skies Logic – mobile-first styles. Large print/high contrast = html.large */
:root {
  --bg: #f6f8fb; --card: #fff; --ink: #1b2430; --muted: #5a6573; --line: #c9d3df;
  --brand: #1f4e79; --brand-2: #f2b134; --accent: #2e7d5b;
  --given-bg: #e6ecf3; --zero: #ffffff; --one: #1f4e79; --one-ink: #fff;
  --sel: #f2b134; --wrong: #c62828; --wrong-bg: #fde3e3;
  --cell: min(13vw, 60px); --radius: 10px; --fs: 17px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.5; }
a { color: var(--brand); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--sel); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: .5rem 1rem; z-index: 9; }
.skip:focus { left: .5rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
[hidden] { display: none !important; }

/* header */
.site-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .75rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .45rem; text-decoration: none; color: var(--ink); font-size: 1.15rem; white-space: nowrap; }
.brand b { color: var(--brand); }
.header-actions { display: flex; gap: .25rem; }
.hbtn { display: inline-flex; align-items: center; gap: .3rem; min-width: 44px; min-height: 44px; justify-content: center; padding: .25rem .5rem; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none; }
.hbtn:hover { background: var(--given-bg); }
.hbtn[aria-pressed="true"] { background: var(--ink); color: #fff; }
.hlabel { display: none; }
@media (min-width: 760px) { .hlabel { display: inline; } }

main { max-width: 760px; margin: 0 auto; padding: .75rem; }
.dayline { text-align: center; }
h1 { font-size: 1.35rem; margin: .25rem 0 0; }
.dayline p { margin: 0 0 .5rem; }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; margin: .5rem 0; }
.tabs [role=tab] { position: relative; min-height: 52px; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--radius); font: inherit; font-weight: 600; cursor: pointer; padding: .3rem; line-height: 1.2; }
.tabs [role=tab] small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.tabs [aria-selected=true] { border-color: var(--brand); background: var(--brand); color: #fff; }
.tabs [aria-selected=true] small { color: #dce8f5; }
.tick { position: absolute; top: 1px; right: 4px; color: var(--accent); font-weight: 800; font-size: .8rem; line-height: 1; }
.tabs [aria-selected=true] .tick { color: var(--brand-2); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .35rem; margin: .5rem 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 4.2em; text-align: center; padding: .4rem .6rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.tbtn { min-height: 44px; padding: .4rem .7rem; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.tbtn:hover:not(:disabled) { border-color: var(--brand); }
.tbtn:disabled { opacity: .45; cursor: default; }
.tbtn[aria-pressed=true] { background: var(--wrong-bg); border-color: var(--wrong); color: var(--wrong); font-weight: 600; }
.rule-hint { text-align: center; color: var(--muted); font-size: .85rem; margin: .25rem 0 .6rem; }

/* board */
.board { display: grid; grid-template-columns: repeat(var(--n), var(--cell)); gap: 3px; justify-content: center; margin: 0 auto; padding: 6px; background: var(--line); border-radius: var(--radius); width: max-content; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.board.n8 { --cell: min(10.6vw, 54px); }
.board.t-k { --cell: min(15vw, 66px); }
.row-w { display: contents; }
.cell { width: var(--cell); height: var(--cell); display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .5); font-weight: 700; border-radius: 6px; background: var(--card); cursor: pointer; position: relative; font-variant-numeric: tabular-nums; }
.cell.given { background: var(--given-bg); cursor: default; }
.t-b6 .cell[data-v="1"], .t-b8 .cell[data-v="1"] { background: var(--one); color: var(--one-ink); }
.t-b6 .cell.given[data-v="1"], .t-b8 .cell.given[data-v="1"] { background: #0f2b45; }
.t-b6 .cell.given[data-v="0"], .t-b8 .cell.given[data-v="0"] { background: var(--given-bg); }
.cell.given::after { content: ""; position: absolute; left: 50%; bottom: 10%; width: 22%; height: 3px; margin-left: -11%; border-radius: 2px; background: currentColor; opacity: .55; }
.t-k .cell.input { color: var(--brand); }
.cell.sel { box-shadow: inset 0 0 0 4px var(--sel); }
.cell.wrong { background: var(--wrong-bg) !important; color: var(--wrong) !important; box-shadow: inset 0 0 0 3px var(--wrong); }
.cell.wrong.sel { box-shadow: inset 0 0 0 4px var(--sel), inset 0 0 0 7px var(--wrong); }
.cell.black { background: #39424e; cursor: default; }
.cell.clue { background: #39424e linear-gradient(to top right, transparent calc(50% - 1px), #aeb8c4 calc(50% - 1px), #aeb8c4 calc(50% + 1px), transparent calc(50% + 1px)); color: #fff; cursor: default; font-size: calc(var(--cell) * .28); }
.clue .ac { position: absolute; top: 6%; right: 10%; }
.clue .dn { position: absolute; bottom: 6%; left: 10%; }
.board.solved { background: var(--accent); }
.board.solved .cell { cursor: default; }
@media (prefers-reduced-motion: no-preference) {
  .board.solved .cell.input { animation: pop .5s ease both; }
  @keyframes pop { 50% { transform: scale(1.08); } }
}

/* pad */
.pad { display: grid; gap: .4rem; justify-content: center; margin: .8rem auto 0; max-width: 420px; }
.pad-b { grid-template-columns: repeat(3, 1fr); }
.pad-k { grid-template-columns: repeat(5, 1fr); }
.pad button { min-height: 52px; font-size: 1.3rem; font-weight: 700; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); cursor: pointer; }
.pad button:active { background: var(--given-bg); }
.pad button:disabled { opacity: .4; }

.done-banner { text-align: center; font-weight: 700; color: var(--accent); margin: .8rem 0 0; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; font: inherit; cursor: pointer; min-height: 32px; }

/* promo / ad */
.ad-slot { margin: 1.25rem auto 0; max-width: 728px; }   /* when ads go live: add min-height to prevent layout shift */
.promo { margin: 1.5rem auto 0; padding: .8rem 1rem; text-align: center; background: #fff8e8; border: 1px solid #f0d9a4; border-radius: var(--radius); }
.promo p { margin: 0; }
.promo-in { font-size: .9rem; background: #fff8e8; padding: .5rem .7rem; border-radius: 8px; }

/* footer */
.site-footer { text-align: center; padding: 1.5rem .75rem 2rem; font-size: .88rem; color: var(--muted); }
.site-footer p { margin: .3rem 0; }

/* dialogs */
dialog { border: 0; border-radius: 14px; padding: 1.25rem 1.25rem 1rem; max-width: min(560px, 94vw); width: 100%; color: var(--ink); background: var(--card); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 25, 40, .55); }
dialog h2 { margin: 0 0 .5rem; font-size: 1.3rem; padding-right: 2rem; }
dialog h3 { margin: 1rem 0 .3rem; font-size: 1.05rem; }
dialog ul { padding-left: 1.2rem; margin: .3rem 0; }
.dlg-close { position: absolute; top: .5rem; right: .5rem; }
.dlg-close button { width: 44px; height: 44px; border: 0; background: none; font-size: 1.2rem; cursor: pointer; color: var(--ink); }
dialog .row { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; margin-top: .75rem; }
dialog button:not(.linkbtn):not(.dlg-close button) { min-height: 44px; padding: .4rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font: inherit; cursor: pointer; color: var(--ink); }
dialog button.primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
#dlg-help > form:last-child { text-align: right; margin-top: .75rem; }
.share { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; font-size: .95rem; line-height: 1.25; white-space: pre-wrap; word-break: break-word; font-family: inherit; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3em; font-size: .85em; background: var(--bg); }
.stat-block h3 { margin: .7rem 0 .2rem; font-size: 1rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .3rem; margin: 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: .35rem; text-align: center; }
.stats dt { font-size: .75rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.2rem; font-weight: 700; }
@media (min-width: 520px) { .stats { grid-template-columns: repeat(6, 1fr); } }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; max-width: 92vw; opacity: 0; transition: .25s; z-index: 20; text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* content pages */
.page { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.page h1 { margin-top: .25rem; }
.page h2 { font-size: 1.1rem; margin-top: 1.4rem; }
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; justify-content: space-between; padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
.archive-list .links { display: flex; gap: .4rem; flex-wrap: wrap; }
.archive-list .links a { display: inline-flex; align-items: center; min-height: 40px; padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; }
.archive-list .links a.done { background: #e6f4ec; border-color: var(--accent); color: var(--accent); }

/* ===== Large print + high contrast ===== */
html.large { --fs: 21px; --ink: #000; --muted: #1a1a1a; --line: #000; --bg: #fff; --card: #fff; --brand: #00266b;
  --given-bg: #d9d9d9; --one: #000; --one-ink: #fff; --sel: #ffcf00; --wrong: #b00000; --wrong-bg: #ffd6d6; --accent: #005a2b; }
html.large .board { --cell: min(15vw, 76px); gap: 4px; background: #000; padding: 4px; }
html.large .board.n8 { --cell: min(11.3vw, 70px); }
html.large .board.t-k { --cell: min(15.5vw, 84px); }
html.large .cell { border-radius: 2px; font-size: calc(var(--cell) * .56); }
html.large .cell.clue, html.large .cell.black { background-color: #000; }
html.large .cell.clue { background-image: linear-gradient(to top right, transparent calc(50% - 1.5px), #fff calc(50% - 1.5px), #fff calc(50% + 1.5px), transparent calc(50% + 1.5px)); font-size: calc(var(--cell) * .3); font-weight: 800; }
html.large .t-b6 .cell.given[data-v="0"], html.large .t-b8 .cell.given[data-v="0"] { background: #d9d9d9; color: #000; }
html.large .t-b6 .cell.given[data-v="1"], html.large .t-b8 .cell.given[data-v="1"] { background: #000; color: #fff; }
html.large .t-b6 .cell.input[data-v="1"], html.large .t-b8 .cell.input[data-v="1"] { background: #00266b; }
html.large .t-k .cell.input { color: #00266b; }
html.large .cell.sel { box-shadow: inset 0 0 0 6px var(--sel); }
html.large .tbtn, html.large .tabs [role=tab], html.large .pad button, html.large .timer { border-width: 2px; border-color: #000; }
html.large .tabs [role=tab] small { color: #000; }
html.large .tabs [aria-selected=true] small { color: #fff; }
html.large .pad { max-width: 520px; }
html.large .pad button { min-height: 64px; font-size: 1.6rem; }
html.large .pad-b { display: grid; }
html.large .promo { background: #fff; border: 2px solid #000; }
html.large a { text-decoration-thickness: 2px; }
html.large :focus-visible { outline: 4px solid #000; box-shadow: 0 0 0 7px var(--sel); }

@media (min-width: 760px) {
  main { padding: 1rem 1.5rem; }
  h1 { font-size: 1.6rem; }
}
@media print {
  .site-header, .tabs, .toolbar, .pad, .promo, .ad-slot, dialog, .skip, .toast { display: none !important; }
}

/* narrow phones: keep header on one line */
@media (max-width: 420px) {
  .site-header { padding: .4rem .5rem; }
  .brand { font-size: 1rem; gap: .35rem; }
  .brand img { width: 28px; height: 28px; }
  .header-actions { gap: 0; }
  .hbtn { min-width: 40px; padding: .2rem .25rem; }
  html.large .brand { font-size: .95rem; }
}
@media (max-width: 359px) { .brand img { display: none; } }
