*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink:      #2e2e2e;
  --paper:    #f7f4ee;
  --def-bg:   #e9e5dc;
  --def-sep:  #cbc6ba;
  --arrow:    #2e2e2e;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  background: #dedad2;
  font-family: Arial, sans-serif;
}

.header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  margin-bottom: -0.75rem;
}

h1 {
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.9rem, 2.5vw, 1.3rem);
  font-weight: normal;
  letter-spacing: .15em;
  color: #4a4a4a;
  user-select: none;
  white-space: nowrap;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.date-label {
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.7rem, 1.8vw, 1rem);
  font-weight: normal;
  color: #6a6a6a;
  user-select: none;
  white-space: nowrap;
}

.hist-link {
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.6rem, 1.4vw, 0.8rem);
  color: #888;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: .04em;
}
.hist-link:hover { color: #4a4a4a; text-decoration: underline; }

.sheet {
  background: var(--paper);
  padding: calc(var(--cell) * 0.35);
  box-shadow: 0 2px 6px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.12);
}

.grid {
  display: grid;
  border: 2px solid var(--ink);
  position: relative;
  z-index: 0;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid var(--ink);
  overflow: hidden;
  position: relative;
}

/* ── Letter cells ── */
.cell.L {
  background: var(--paper);
}

/* ── Definition cells ── */
.cell.D {
  background: var(--def-bg);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 2px;
  gap: 0;
}

.cell.D .w {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-family: 'Arial Narrow', Arial, sans-serif;
  font-weight: bold;
  font-size: calc(var(--cell) * 0.175);
  line-height: 1.15;
  text-align: center;
  overflow: hidden;
  word-break: break-word;
  white-space: normal;
  width: 100%;
  border-top: 1px solid var(--def-sep);
}
.cell.D .w:first-child { border-top: none; }
.cell.D.n2 .w { font-size: calc(var(--cell) * 0.145); }
.cell.D.n3 .w { font-size: calc(var(--cell) * 0.115); }
.cell.D.n4 .w { font-size: calc(var(--cell) * 0.095); }

/* ── Arrows on letter cells ── */
.a {
  position: absolute;
  font-size: calc(var(--cell) * 0.32);
  line-height: 1;
  color: var(--arrow);
  pointer-events: none;
  z-index: 1;
}

/* ── Typed letter ── */
.letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.48);
  font-weight: bold;
  font-family: 'Courier New', Courier, monospace;
  color: var(--ink);
  pointer-events: none;
  z-index: 0;
}

/* ── Legend ── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: center;
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  color: #6a6a6a;
  user-select: none;
  margin-bottom: 2rem;
}
kbd {
  display: inline-block;
  background: #e8e4dc;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 0 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.7rem;
  line-height: 1.5;
  color: #3a3a3a;
}

/* ── Interactive selection ── */
.cell.L { cursor: pointer; }
.cell.L.wsel { background: #dbeafe; }
.cell.L.csel { background: #93c5fd; }
.cell.D.dsel { background: #bfcfe0; }

/* ── Validation states ── */
.cell.L.wrong  { background: #fecaca; }
.cell.L.wrong.csel { background: #f87171; }
.cell.L.wrong.wsel { background: #fca5a5; }
.cell.L.sol    { background: #fef9c3; }
.cell.L.sol.csel { background: #fde047; }
.cell.L.sol.wsel { background: #fef08a; }

/* ── Result banner ── */
.result-banner {
  padding: 0.55rem 1rem;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.75rem, 2vw, 0.95rem);
  text-align: center;
  display: none;
}
.result-banner.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  display: block;
}
.result-banner.errors {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  display: block;
}

/* ── Solution button ── */
.sol-btn {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  background: var(--paper);
  color: #4a4a4a;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  user-select: none;
  letter-spacing: .05em;
}
.sol-btn:hover { background: var(--def-bg); }
.sol-btn.active { background: #fef9c3; border-color: #ca8a04; color: #713f12; }

.btn-row {
  display: flex;
  gap: 0.5rem;
}

/* ── Day navigation ── */
.grid-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.day-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.8rem;
  height: 2.8rem;
  font-size: 2rem;
  color: #7a7570;
  text-decoration: none;
  background: transparent;
  border: 1.5px solid #b0aa9f;
  border-radius: 50%;
  flex-shrink: 0;
  user-select: none;
  transition: border-color .15s, color .15s;
}
.day-nav:hover { border-color: #4a4a4a; color: #1a1a1a; }
.day-nav.disabled { opacity: 0.25; pointer-events: none; }

/* ── Print footer (hidden on screen) ── */
.print-footer { display: none; }

/* ── Print styles ── */
@media print {
  @page { size: A4 landscape; margin: 0.7cm; }

  :root {
    --ink:     #000;
    --paper:   #fff;
    --def-bg:  #eaeaea;
    --def-sep: #999;
    --arrow:   #000;
  }

  body {
    background: #fff !important;
    min-height: unset;
    justify-content: flex-start;
    gap: 0.4rem;
  }

  /* Hide all non-essential UI */
  h1,
  .btn-row,
  .legend,
  .result-banner,
  .result-banner.success,
  .result-banner.errors,
  .hist-link,
  .day-nav,
  .header-right { display: none !important; }

  .sheet { box-shadow: none !important; background: #fff !important; }

  /* Remove interactive highlight colours */
  .cell.L,
  .cell.L.wsel,
  .cell.L.csel,
  .cell.L.wrong,
  .cell.L.sol   { background: var(--paper) !important; }
  .cell.D,
  .cell.D.dsel  { background: var(--def-bg) !important; }

  .print-footer {
    display: block;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.65rem;
    color: #555;
    letter-spacing: .06em;
    margin-top: 0.3rem;
  }
}
