:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #fffdf8;
  --ink: #181612;
  --muted: #615b50;
  --line: #d3ccc0;
  --strong-line: #171512;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --secondary: #8a5a16;
  --secondary-ink: #ffffff;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 280px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100% - 32px, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 32px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.day-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.nav-link,
.dialog-close {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.9);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.nav-link:hover,
.dialog-close:hover {
  border-color: var(--muted);
  background: var(--surface);
  transform: translateY(-1px);
}

.nav-link:focus-visible,
.dialog-close:focus-visible,
.action-button:focus-visible,
.history-date:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.print-surface {
  display: grid;
  gap: 18px;
}

.page-heading {
  text-align: center;
}

.page-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 4.35rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: 0;
}

.date-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(1.12rem, 2.4vw, 1.55rem);
  font-weight: 650;
}

.puzzle-section {
  width: min(100%, 700px);
  margin: 0 auto;
}

.sudoku-grid {
  width: min(100%, 70vh, 700px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  border: 3px solid var(--strong-line);
  background: var(--strong-line);
  box-shadow: 0 18px 44px rgba(37, 31, 22, 0.14);
}

.sudoku-cell {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 6.2vw, 3.15rem);
  font-weight: 700;
  line-height: 1;
}

.sudoku-cell:nth-child(3n) {
  border-right-color: var(--strong-line);
  border-right-width: 3px;
}

.sudoku-cell:nth-child(9n) {
  border-right-width: 0;
}

.sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom-color: var(--strong-line);
  border-bottom-width: 3px;
}

.sudoku-cell:nth-child(n + 73):nth-child(-n + 81) {
  border-bottom-width: 0;
}

.sudoku-cell.is-empty {
  color: transparent;
}

.primary-actions {
  width: min(100%, 700px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.action-button {
  min-height: 64px;
  padding: 15px 18px;
  border: 0;
  border-radius: 8px;
  color: var(--accent-ink);
  font-size: clamp(1.05rem, 2.8vw, 1.35rem);
  font-weight: 780;
  letter-spacing: 0;
  box-shadow: 0 12px 24px rgba(24, 22, 18, 0.14);
  transition:
    filter 160ms ease,
    transform 160ms ease;
}

.action-button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.action-button:active {
  transform: translateY(0);
}

.action-button-print {
  background: var(--accent);
}

.action-button-pdf {
  background: var(--secondary);
}

.weather-widget {
  width: 100%;
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.86);
}

.weather-widget[hidden] {
  display: none !important;
}

.weather-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.weather-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  color: var(--ink);
  display: inline-flex;
}

.weather-icon svg {
  width: 100%;
  height: 100%;
}

.weather-header {
  min-width: 0;
}

.weather-location,
.weather-label,
.weather-attribution {
  margin: 0;
}

.weather-location,
.weather-attribution {
  color: var(--muted);
  font-size: 0.82rem;
}

.weather-label {
  font-size: 1rem;
  font-weight: 760;
  line-height: 1.2;
}

.weather-details {
  margin: 10px 0 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.weather-days {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 235px), 1fr));
  gap: 8px;
}

.weather-day {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
}

.weather-day h3,
.weather-day-label {
  margin: 0;
}

.weather-day h3 {
  font-size: 0.86rem;
  line-height: 1.15;
}

.weather-day-icon {
  width: 28px;
  height: 28px;
  margin: 5px 0 3px;
  color: var(--ink);
  display: inline-flex;
}

.weather-day-icon svg {
  width: 100%;
  height: 100%;
}

.weather-day-label {
  font-size: 0.82rem;
  font-weight: 720;
  line-height: 1.2;
}

.weather-day .weather-details {
  margin-top: 6px;
  grid-template-columns: 1fr;
  gap: 3px;
}

.weather-day .weather-detail {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.weather-detail {
  min-width: 0;
}

.weather-detail dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.weather-detail dd {
  margin: 1px 0 0;
  font-size: 0.86rem;
  line-height: 1.25;
}

.weather-day .weather-detail dd {
  white-space: nowrap;
}

.weather-attribution {
  margin-top: 8px;
}

.tv-listings-widget {
  width: 100%;
  margin: 0 auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.86);
}

.tv-listings-widget[hidden] {
  display: none !important;
}

.tv-listings-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.tv-listings-header h2,
.tv-listings-header p,
.tv-listings-channel h3,
.tv-listings-channel ul,
.tv-listings-unavailable {
  margin: 0;
}

.tv-listings-header h2 {
  font-size: clamp(1.2rem, 2vw, 1.45rem);
  line-height: 1.2;
}

.tv-listings-header p {
  color: var(--muted);
  font-size: clamp(0.98rem, 1.5vw, 1.12rem);
  font-weight: 650;
}

.tv-listings-channels {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.tv-listings-channel {
  min-width: 0;
  padding: 10px 9px;
  border: 1px solid rgba(211, 204, 192, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.tv-listings-channel h3 {
  font-size: clamp(1rem, 1.35vw, 1.12rem);
  line-height: 1.2;
  font-weight: 800;
}

.tv-listings-channel ul {
  padding: 0;
  list-style: none;
}

.tv-listings-channel li {
  margin-top: 7px;
  display: grid;
  grid-template-columns: minmax(3.35em, max-content) minmax(0, 1fr);
  gap: 0.45em;
  font-size: clamp(0.96rem, 1.2vw, 1.08rem);
  line-height: 1.22;
}

.tv-listings-channel time {
  color: var(--ink);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  justify-self: start;
  white-space: nowrap;
}

.tv-listings-channel li > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tv-listing-empty,
.tv-listings-unavailable {
  color: var(--muted);
  font-size: clamp(0.96rem, 1.2vw, 1.08rem);
}

.tv-listings-unavailable {
  font-weight: 700;
}

.status-text {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.status-text.is-error {
  color: #9f1239;
  font-weight: 650;
}

.history-dialog {
  width: min(92vw, 440px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(24, 22, 18, 0.32);
}

.history-dialog::backdrop {
  background: rgba(24, 22, 18, 0.44);
}

.dialog-panel {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

.dialog-close {
  min-height: 36px;
  padding: 7px 12px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-date {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-date:hover {
  border-color: var(--accent);
}

.history-date[aria-current="date"] {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 760;
}

.visually-hidden {
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  position: absolute;
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 14px;
    gap: 14px;
  }

  .day-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .nav-link {
    min-height: 40px;
    padding: 8px 7px;
    font-size: 0.92rem;
    text-align: center;
  }

  .sudoku-grid {
    width: min(100%, 88vh);
  }

  .primary-actions {
    grid-template-columns: 1fr;
  }

  .action-button {
    min-height: 58px;
  }

  .weather-widget {
    padding: 11px 12px;
  }

  .weather-details {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weather-days {
    grid-template-columns: 1fr;
  }

  .weather-day .weather-detail dd {
    white-space: normal;
  }

  .tv-listings-header {
    display: block;
  }

  .tv-listings-channels {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .tv-listings-channel {
    padding: 10px;
  }

  .tv-listings-channel li {
    grid-template-columns: minmax(3.35em, max-content) minmax(0, 1fr);
  }

}

@media (min-width: 641px) and (max-width: 980px) {
  .tv-listings-channels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tv-listings-channel:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@page {
  size: A4 portrait;
  margin: 14mm;
}

@media print {
  :root {
    --surface: #ffffff;
    --ink: #000000;
    --line: #000000;
    --strong-line: #000000;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #ffffff !important;
    color: #000000 !important;
  }

  body * {
    visibility: hidden !important;
  }

  .print-surface,
  .print-surface * {
    visibility: visible !important;
  }

  .no-print,
  .history-dialog {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    min-height: auto;
    margin: 0;
    padding: 0;
    display: block;
  }

  .print-surface {
    position: absolute;
    inset: 0;
    display: block;
  }

  .page-heading {
    margin: 0 0 4mm;
    text-align: center;
  }

  .page-heading h1 {
    font-size: 20pt;
    line-height: 1.1;
  }

  .date-text {
    margin-top: 1.5mm;
    color: #000000;
    font-size: 11pt;
  }

  .puzzle-section {
    width: 100%;
    margin: 0;
  }

  .sudoku-grid {
    width: 145mm;
    max-width: 100%;
    margin: 0 auto;
    border: 2pt solid #000000;
    box-shadow: none;
    background: #000000;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .sudoku-cell {
    border: 0.75pt solid #000000;
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 21pt;
  }

  .sudoku-cell:nth-child(3n) {
    border-right-width: 2pt;
  }

  .sudoku-cell:nth-child(9n) {
    border-right-width: 0;
  }

  .sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
  .sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
    border-bottom-width: 2pt;
  }

  .sudoku-cell:nth-child(n + 73):nth-child(-n + 81) {
    border-bottom-width: 0;
  }

  .sudoku-cell.is-empty {
    color: transparent !important;
  }

  .weather-widget {
    width: 180mm;
    max-width: 100%;
    margin: 4mm auto 0;
    padding: 2mm 3mm;
    border: 0.75pt solid #000000;
    border-radius: 0;
    color: #000000 !important;
    background: #ffffff !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .weather-summary {
    gap: 2mm;
  }

  .weather-icon {
    width: 7mm;
    height: 7mm;
    color: #000000;
  }

  .weather-location,
  .weather-attribution {
    color: #000000;
    font-size: 6pt;
  }

  .weather-label {
    font-size: 8pt;
  }

  .weather-details {
    margin-top: 2mm;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2mm;
  }

  .weather-days {
    margin-top: 1.5mm;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1mm;
  }

  .weather-day {
    padding: 1mm;
    border: 0.5pt solid #000000;
    border-radius: 0;
    background: #ffffff !important;
  }

  .weather-day h3 {
    font-size: 6pt;
  }

  .weather-day-icon {
    width: 5mm;
    height: 5mm;
    margin: 0.5mm 0 0.25mm;
    color: #000000;
  }

  .weather-day-label {
    font-size: 5.8pt;
  }

  .weather-day .weather-details {
    margin-top: 1mm;
    grid-template-columns: 1fr;
    gap: 0.7mm;
  }

  .weather-day .weather-detail {
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 1mm;
  }

  .weather-detail dt {
    color: #000000;
    font-size: 5.4pt;
  }

  .weather-detail dd {
    font-size: 5.8pt;
  }

  .weather-day .weather-detail dd {
    white-space: nowrap;
  }

  .weather-attribution {
    margin-top: 2mm;
  }

  .tv-listings-widget {
    width: 180mm;
    max-width: 100%;
    margin: 3mm auto 0;
    padding: 2mm 3mm;
    border: 0.75pt solid #000000;
    border-radius: 0;
    color: #000000 !important;
    background: #ffffff !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .tv-listings-header h2 {
    font-size: 8pt;
  }

  .tv-listings-header p {
    color: #000000;
    font-size: 6pt;
  }

  .tv-listings-channels {
    margin-top: 1.5mm;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1.5mm;
  }

  .tv-listings-channel h3 {
    font-size: 6pt;
  }

  .tv-listings-channel li {
    margin-top: 0.8mm;
    grid-template-columns: 8mm minmax(0, 1fr);
    gap: 1mm;
    font-size: 5.7pt;
    line-height: 1.12;
  }

  .tv-listings-channel time,
  .tv-listing-empty,
  .tv-listings-unavailable {
    color: #000000;
  }

  .tv-listings-unavailable {
    font-size: 8pt;
  }

}
