:root {
  color-scheme: light dark;
  --ground: #f6f4fa;
  --sunk: #ebe7f4;
  --ink: #1c1a24;
  --quiet: #56516b;
  --edge: #6c6785;
  --break: #6d28d9;
  --on-break: #ffffff;
  --break-soft: #e8defb;
  --break-ink: #5b21b6;
  --solved: #4c1d95;
  --on-solved: #ffffff;
  --focus: #18181b;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

body {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  margin: 0;
}

main {
  flex: 1;
  width: min(100%, 40rem);
  margin: 0 auto;
  padding: 1.5rem max(1rem, env(safe-area-inset-right)) 3rem max(1rem, env(safe-area-inset-left));
}

main:has(#puzzle-screen:not([hidden])) {
  width: min(100%, 70rem);
  padding: 1rem 1.5rem 1.5rem;
}

[hidden] {
  display: none !important;
}

h1 {
  display: flex;
  gap: 5px;
  margin: 0 0 1.1rem;
}

.wordmark-slot {
  display: inline-block;
  width: 1.55rem;
  padding-bottom: 1px;
  border-bottom: 3px solid var(--edge);
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

.wordmark-slot-break {
  border-bottom-color: var(--break);
}

h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.2;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.95rem;
  font-weight: 780;
  letter-spacing: -0.02em;
}

h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
}

p {
  margin: 0 0 1rem;
}

label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 650;
}

input,
button,
textarea {
  font: inherit;
  color: var(--ink);
}

input {
  width: 100%;
  min-height: 44px;
  border: 2px solid var(--edge);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  background: var(--sunk);
}

textarea {
  border: 2px solid var(--edge);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  background: var(--sunk);
  resize: vertical;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 2px solid var(--break);
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  background: var(--break);
  color: var(--on-break);
  font-weight: 700;
  cursor: pointer;
}

button.secondary,
button.quiet {
  border-color: var(--edge);
  background: transparent;
  color: var(--break-ink);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

button:focus-visible,
textarea:focus-visible,
footer a:focus-visible,
footer button.footer-link:focus-visible,
main > p > a:focus-visible,
html.keyboard #guess-input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

#guess-input:focus {
  border-color: var(--break);
  outline: none;
}

[tabindex="-1"]:focus {
  outline: none;
}

.puzzle-meta,
.storage-note {
  color: var(--quiet);
}

.countdown-ticking {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 750;
}

.clue-list {
  display: grid;
  gap: 0.1rem;
  margin: 0 0 0 -0.55rem;
  padding: 0;
  list-style: none;
}

.clue-rule {
  display: grid;
  grid-template-columns: 1.3rem 1.8rem 1fr;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.4rem;
  padding: 0.1rem 0.55rem;
  border-radius: 10px;
}

.clue-number {
  color: var(--quiet);
  font-weight: 700;
  text-align: left;
}

.clue-mark {
  display: grid;
  width: 1.6rem;
  height: 1.6rem;
  place-items: center;
  border-radius: 7px;
  color: var(--quiet);
}

.clue-mark svg {
  width: 1rem;
  height: 1rem;
}

.clue-rule-broken {
  background: var(--break-soft);
  font-weight: 650;
}

.clue-rule-broken .clue-mark {
  background: var(--break);
  color: var(--on-break);
}

.clue-rule-locked {
  color: var(--quiet);
}

.clue-rule-locked .clue-mark {
  border: 2px dashed var(--edge);
}

.guess-heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

.guess-heading-row label {
  margin-bottom: 0.4rem;
}

.guess-counter {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.4rem auto;
  color: var(--quiet);
  font-size: 0.8rem;
  font-weight: 700;
}

.guess-slots {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 16px;
}

.guess-slot {
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 2px solid var(--edge);
  color: var(--edge);
}

.guess-slot svg {
  width: 12px;
  height: 12px;
}

.guess-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}

#guess-input {
  flex: 1 1 14rem;
  width: auto;
  min-width: 0;
  height: 52px;
  padding: 0 0.9rem;
  border-radius: 10px;
  background: var(--sunk);
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.guess-row button {
  height: 52px;
  padding: 0 1.25rem;
}

.share-controls {
  display: grid;
  grid-template-columns: auto auto minmax(8rem, 1fr);
  gap: 0.6rem;
  align-items: start;
}

.share-controls button {
  height: 52px;
  padding: 0 1.25rem;
  white-space: nowrap;
}

.share-controls .status,
.popup-share-status {
  min-height: 2.8em;
  margin: 0;
}

.share-controls textarea,
dialog textarea {
  width: 100%;
  min-height: 5rem;
  grid-column: 1 / -1;
}

#puzzle-screen h2 {
  margin: 0;
  line-height: 1.1;
}

#puzzle-heading::after {
  display: block;
  width: 2.6rem;
  height: 4px;
  margin-top: 0.4rem;
  border-radius: 2px;
  background: var(--break);
  content: "";
}

#puzzle-meta {
  margin: 0.7rem 0 0;
}

#clues-shown {
  height: 1.4em;
  margin: 0.15rem 0 0.9rem;
  font-size: 0.92rem;
}

#streak-line {
  margin: -0.9rem 0 0.9rem;
  white-space: nowrap;
}

#streak-status {
  margin: -0.6rem 0 0.9rem;
  font-weight: 650;
}

#streak-status:empty {
  display: none;
}

.new-puzzle-note {
  margin-top: 1rem;
  color: var(--quiet);
}

.new-puzzle-note button {
  margin-left: 0.5rem;
}

main:has(#puzzle-screen:not([hidden])) > h1 {
  margin-bottom: 1.1rem;
}

.puzzle-play {
  margin-top: 1rem;
}

.status {
  min-height: 1.6em;
  margin-top: 0.8rem;
  font-weight: 650;
}

.status button {
  margin-left: 0.75rem;
}

#puzzle-screen .status {
  min-height: 2.9em;
  margin: 0.8rem 0 0;
}

#puzzle-screen .share-controls .status {
  min-height: 2.8em;
  margin: 0;
}

#puzzle-screen h3 {
  margin: 1.5rem 0 0.6rem;
  font-size: 1.02rem;
  font-weight: 700;
}

.guess-list {
  display: grid;
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guess-visual {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem 1.7rem;
}

.letter-tiles,
.rule-cells {
  display: flex;
  flex: none;
  max-width: 100%;
}

.letter-tiles {
  gap: 6px;
}

.rule-cells {
  gap: 4px;
}

.letter-tile {
  width: 44px;
  padding-bottom: 2px;
  border-bottom: 4px solid var(--edge);
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.letter-tile-solved {
  border-bottom-color: var(--solved);
}

.rule-cell {
  display: grid;
  width: 34px;
  height: 46px;
  place-content: center;
  justify-items: center;
  gap: 2px;
  border-radius: 8px;
  color: var(--quiet);
  font-size: 0.74rem;
  line-height: 1;
}

.rule-cell svg {
  width: 15px;
  height: 15px;
}

.rule-cell-broken {
  background: var(--break);
  color: var(--on-break);
}

.rule-cell-locked {
  border: 2px dashed var(--edge);
}

.broken-rules {
  margin: 0;
  padding: 0;
  list-style: none;
}

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

footer {
  flex: none;
  color: var(--quiet);
  font-size: 0.8rem;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  width: min(100%, 70rem);
  margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left));
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
}

.footer-countdown,
.footer-copyright {
  margin: 0;
}

.footer-countdown {
  white-space: nowrap;
}

.footer-meta,
.footer-socials {
  display: flex;
  align-items: center;
}

.footer-meta {
  flex-wrap: wrap;
  gap: 1.5rem;
}

.footer-socials {
  gap: 1rem;
}

footer a,
footer button.footer-link {
  display: inline-flex;
  min-width: 44px;
  min-height: 44px;
  padding: 0.6rem 0;
  align-items: center;
  justify-content: center;
  color: var(--quiet);
  text-decoration: underline;
}

footer button.footer-link {
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

main > p > a {
  display: inline-flex;
  min-width: 44px;
  min-height: 44px;
  padding: 0.6rem 0;
  align-items: center;
  justify-content: center;
  color: var(--quiet);
  text-decoration: underline;
}

dialog {
  width: min(30rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 1.5rem 1.6rem 1.4rem;
  border: 2px solid var(--edge);
  border-radius: 16px;
  background: var(--ground);
  color: var(--ink);
  overflow-y: auto;
}

dialog::backdrop {
  background: rgba(20, 14, 32, 0.6);
}

.popup-heading {
  margin: 0 0 0.8rem;
  font-size: 1.7rem;
  font-weight: 780;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

dialog p {
  margin: 0 0 1rem;
}

.popup-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

.popup-buttons button {
  height: 52px;
  padding: 0 1.25rem;
  white-space: nowrap;
}

.popup-buttons:has(> button:only-child) {
  justify-content: center;
}

.popup-share-status {
  margin-top: 0.6rem;
}

.answer-slots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0.2rem 0 0.3rem;
}

.answer-slot {
  flex: 0 0 52px;
  width: 52px;
  padding-bottom: 2px;
  border-bottom: 4px solid var(--edge);
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.answer-slots.solved .answer-slot {
  border-bottom-color: var(--solved);
}

dialog:has(.answer-slots) {
  text-align: center;
}

dialog:has(.answer-slots) .popup-buttons {
  justify-content: center;
}

@media (max-width: 39.999rem) {
  .footer-content,
  .footer-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }

  .footer-content {
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-left: max(1rem, env(safe-area-inset-left));
  }

  .footer-countdown {
    white-space: normal;
  }
}

@media (max-width: 30rem) {
  .share-controls {
    grid-template-columns: 1fr;
  }

  .share-controls button,
  .popup-buttons button {
    width: 100%;
  }

  dialog:has(.answer-slots) .popup-buttons {
    flex-direction: column;
  }

  .answer-slot {
    flex-basis: min(52px, calc((100% - 30px) / 6));
  }
}

@media (max-width: 23.499rem) {
  .letter-tile {
    width: 39px;
  }

  .rule-cell {
    width: 30px;
  }
}

@media (min-width: 56rem) {
  #puzzle-screen {
    display: grid;
    grid-template-columns: minmax(0, 27rem) minmax(0, 1fr);
    gap: 3.2rem;
    align-items: start;
  }

  .puzzle-play {
    margin-top: 0;
  }
}

@media (min-width: 56rem) and (max-width: 72rem) {
  #puzzle-screen {
    grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
    gap: 2rem;
  }

  .guess-visual {
    column-gap: 1.1rem;
  }

  .letter-tiles {
    gap: 5px;
  }

  .letter-tile {
    width: 40px;
    font-size: 1.65rem;
  }

  .rule-cells {
    gap: 3px;
  }

  .rule-cell {
    width: 31px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #1b1923;
    --sunk: #27242f;
    --ink: #f4f2f9;
    --quiet: #c5bfd8;
    --edge: #8e88a8;
    --break: #7d3bee;
    --on-break: #ffffff;
    --break-soft: #33264f;
    --break-ink: #cdbcff;
    --solved: #8b4df0;
    --on-solved: #ffffff;
    --focus: #f4f2f9;
  }
}
