:root {
  --bg: #f3f6f4;
  --ink: #17201c;
  --muted: #66736d;
  --line: #cbd6d0;
  --panel: #ffffff;
  --accent: #256d85;
  --accent-dark: #164f62;
  --hint: #7c3aed;
  --hint-dark: #ffffff;
  --reveal: #9a5b2f;
  --reveal-dark: #ffffff;
  --secondary: #4f7f72;
  --secondary-dark: #3f695d;
  --target: #8a5a00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  touch-action: manipulation;
}

button:focus-visible,
.neighbor:focus-visible {
  outline: 3px solid rgba(37, 109, 133, 0.24);
  outline-offset: 2px;
}

.shell {
  width: min(920px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar,
.status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
}

.topbar {
  padding-bottom: 4px;
  border-bottom: 0;
}

.wordmark-menu {
  position: relative;
  justify-self: start;
}

.wordmark {
  appearance: none;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.45rem;
  font-weight: 850;
  text-decoration: none;
}

.wordmark span:first-child {
  color: var(--ink);
}

.wordmark::after {
  content: "";
  width: 0.36em;
  height: 0.36em;
  margin-left: 1px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-0.18em) rotate(45deg);
}

.wordmark-mode.daily {
  color: var(--accent);
}

.wordmark-mode.freeplay {
  color: var(--hint);
}

.mode-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 8;
  display: grid;
  gap: 2px;
  min-width: 132px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(23, 32, 28, 0.16);
}

.mode-menu[hidden] {
  display: none;
}

.mode-menu a {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border-radius: 5px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: left;
  text-decoration: none;
}

.mode-menu a.active {
  background: #eef7f4;
  color: var(--accent-dark);
}

.mode-menu #freeplayModeButton.active {
  background: rgba(124, 58, 237, 0.09);
  color: var(--hint);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(2.4rem, 7vw, 5.4rem);
  line-height: 0.95;
}

button,
.neighbor {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 750;
}

button {
  min-width: 112px;
  padding: 10px 14px;
}

.outline-button {
  border-color: rgba(37, 109, 133, 0.55);
  background: transparent;
  color: var(--accent);
}

.help-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.08rem;
  line-height: 1;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.status {
  justify-content: center;
  margin: 8px 0 4px;
  padding-bottom: 0;
  border-bottom: 0;
  text-align: center;
}

.status strong {
  display: block;
  margin-top: 0;
  color: var(--ink);
  font-size: clamp(2.6rem, 6vw, 4.8rem);
  line-height: 0.95;
}

.target-prompt {
  display: block;
  color: var(--ink);
  font-size: clamp(1.15rem, 2.4vw, 1.7rem);
  font-weight: 750;
  line-height: 1;
}

.word-nav {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
  overflow-x: hidden;
  overflow-y: clip;
  touch-action: pan-x;
}

.path {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  justify-content: flex-end;
  gap: 8px;
  min-height: 1em;
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.path::-webkit-scrollbar {
  display: none;
}

.path-word {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 750;
}

.path-word:not(.current)::after {
  content: "/";
  margin-left: 8px;
  color: #9aa7a1;
  font-weight: 500;
}

.path-word.current {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  margin-bottom: 0;
  color: var(--muted);
  cursor: default;
  font-size: 0.94rem;
  font-weight: 850;
  line-height: 1;
  max-width: min(38vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 1;
  text-align: center;
}

.path-word:disabled {
  cursor: default;
  opacity: 1;
}

.word-nav-actions {
  display: contents;
}

.move-count {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  color: var(--ink);
  font-size: 1.58rem;
  font-weight: 850;
  line-height: 1;
}

.undo-button {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
  justify-self: end;
  position: static;
  transform: none;
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.86rem;
}

.play-area {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.assist-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.assist-controls button {
  border-color: var(--secondary);
  background: var(--secondary);
  min-width: 0;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.assist-controls button.active {
  border-color: var(--reveal);
  background: var(--reveal);
}

.assist-output {
  min-height: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  overflow: hidden;
}

.assist-path {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.assist-path span {
  color: var(--ink);
  font-weight: 750;
}

.assist-path span:not(:last-child)::after {
  content: ">";
  margin-left: 8px;
  color: #9aa7a1;
  font-weight: 500;
}

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

.neighbor-grid.win-layout {
  display: block;
}

.neighbor {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-items: center;
  padding: 10px 12px;
  text-align: center;
  text-decoration: none;
}

.neighbor.hint {
  border-color: var(--hint);
  background: var(--hint);
  color: var(--hint-dark);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.22);
}

.neighbor.reveal {
  border-color: var(--reveal);
  background: var(--reveal);
  color: var(--reveal-dark);
  box-shadow: 0 0 0 3px rgba(154, 91, 47, 0.2);
}

button:active,
.neighbor:active {
  background: var(--accent-dark);
}

.assist-controls button:active {
  background: var(--secondary-dark);
}

.outline-button:active {
  background: rgba(37, 109, 133, 0.12);
}

.wordmark:active {
  background: transparent !important;
  color: var(--ink) !important;
}

.win-panel .win-details:active {
  border-color: rgba(37, 109, 133, 0.65);
  background: rgba(37, 109, 133, 0.12) !important;
  color: var(--accent-dark) !important;
}

.assist-controls button.active:active,
.neighbor.reveal:active {
  background: #804925;
}

.neighbor.hint:active {
  background: #6427c9;
}

@media (hover: hover) and (pointer: fine) {
  button:hover,
  .neighbor:hover {
    background: var(--accent-dark);
  }

  .path-word:hover {
    background: transparent;
    color: var(--accent-dark);
  }

  .assist-controls button:hover {
    background: var(--secondary-dark);
  }

  .outline-button:hover {
    background: rgba(37, 109, 133, 0.1);
    color: var(--accent-dark);
  }

  .wordmark:hover {
    background: transparent !important;
    color: var(--ink) !important;
  }

  .mode-menu a:hover {
    background: #eef7f4 !important;
    color: var(--accent-dark) !important;
  }

  .mode-menu #freeplayModeButton:hover {
    background: rgba(124, 58, 237, 0.09) !important;
    color: var(--hint) !important;
  }

  .win-panel .win-details:hover {
    border-color: rgba(37, 109, 133, 0.65);
    background: rgba(37, 109, 133, 0.1) !important;
    color: var(--accent-dark) !important;
  }

  .assist-controls button.active:hover,
  .neighbor.reveal:hover {
    background: #804925;
  }

  .neighbor.hint:hover {
    background: #6427c9;
  }
}

.win {
  border-color: rgba(37, 109, 133, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #eef7f4 100%);
}

.win .assist-output,
.win .assist-controls {
  display: none;
}

.win-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-height: 270px;
  padding: 42px 24px;
  border: 1px solid rgba(37, 109, 133, 0.22);
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  box-shadow: 0 14px 32px rgba(25, 42, 35, 0.08);
}

.win-panel h2 {
  color: var(--ink);
  font-size: clamp(1.9rem, 5vw, 3.35rem);
  line-height: 0.95;
}

.win-word {
  color: var(--accent);
  font-size: clamp(2.3rem, 7vw, 4.8rem);
  line-height: 0.95;
  overflow-wrap: anywhere;
}

.win-summary {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 700;
}

.win-details,
.win-copy,
.win-new-game {
  min-width: 146px;
}

.win-details {
  margin-top: 8px;
}

.win-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.win-details {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-color: rgba(37, 109, 133, 0.55);
  background: transparent;
  color: var(--accent);
}

.win-details svg,
.win-copy svg {
  flex: 0 0 auto;
  fill: currentColor;
}

.win-puzzle {
  margin: 0;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 850;
}

.win-new-game {
  margin-top: 0;
}

.message {
  color: var(--muted);
}

.details-dialog {
  width: min(640px, calc(100vw - 28px));
  max-height: min(720px, calc(100dvh - 36px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.howto-dialog {
  width: min(520px, calc(100vw - 28px));
}

.details-dialog::backdrop {
  background: rgba(23, 32, 28, 0.42);
}

.details-modal {
  max-height: inherit;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(23, 32, 28, 0.24);
}

.details-head {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.details-head h2 {
  font-size: 1.2rem;
}

.details-content {
  display: grid;
  gap: 18px;
  max-height: calc(min(720px, calc(100dvh - 36px)) - 136px);
  overflow: auto;
  padding: 20px;
}

.howto-content {
  text-align: center;
}

.howto-content p {
  margin: 0;
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 650;
  line-height: 1.55;
}

.howto-path {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  justify-self: center;
  max-width: 100%;
}

.details-foot {
  display: flex;
  justify-content: center;
  padding: 16px 20px 18px;
  border-top: 1px solid var(--line);
}

.details-close {
  min-width: 112px;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.9rem;
}

.details-section {
  display: grid;
  gap: 8px;
}

.details-section h3 {
  margin: 0;
  font-size: 1rem;
}

.details-count {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.details-path {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.details-word {
  border: 1px solid rgba(37, 109, 133, 0.16);
  border-radius: 6px;
  background: #eef7f4;
  color: var(--accent-dark);
  padding: 6px 8px;
  font-weight: 800;
}

.details-divider {
  color: #9aa7a1;
  font-weight: 700;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .shell {
    width: min(100% - 20px, 560px);
    max-width: 100%;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    justify-items: stretch;
    padding-bottom: 2px;
    border-bottom: 0;
  }

  .wordmark {
    font-size: 1.25rem;
  }

  .top-actions {
    gap: 8px;
  }

  button {
    min-height: 44px;
  }

  #newGameButton {
    min-width: 0;
    min-height: 36px;
    padding: 7px 10px;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  #howToButton {
    width: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    font-size: 1rem;
  }

  .status {
    display: flex;
    justify-content: center;
    margin: 6px 0 2px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .status > div {
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .target-status {
    text-align: center;
  }

  .status strong {
    font-size: 1rem;
    overflow-wrap: anywhere;
  }

  .status > div:first-child strong {
    font-size: clamp(2.1rem, 12vw, 3.35rem);
    line-height: 0.95;
  }

  .target-prompt {
    font-size: clamp(1.05rem, 5vw, 1.45rem);
    line-height: 0.95;
  }

  .label {
    font-size: 0.62rem;
  }

  .assist-path {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
  }

  .word-nav {
    margin-bottom: -4px;
  }

  .path {
    align-self: center;
    min-height: 0;
    margin: 0;
    padding: 0;
    font-size: 0.82rem;
    overflow-x: auto;
    overflow-y: clip;
    white-space: nowrap;
    touch-action: pan-x;
  }

  .assist-path span {
    flex: 0 0 auto;
  }

  .path-word {
    font-size: 0.92rem;
    line-height: 1;
  }

  .path-word.current {
    font-size: 0.92rem;
    line-height: 1;
    margin-bottom: 0;
    max-width: min(42vw, 260px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .word-nav-actions {
    display: contents;
  }

  .move-count {
    font-size: 1.5rem;
  }

  .undo-button {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 0.82rem;
  }

  .play-area {
    min-height: 0;
    min-width: 0;
    display: grid;
    grid-template-rows: minmax(16px, auto) minmax(0, 1fr) auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .play-area.win {
    grid-template-rows: minmax(0, 1fr);
    padding-top: 12px;
  }

  .panel-head {
    gap: 6px;
    margin-bottom: 5px;
  }

  .assist-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: flex-start;
    align-items: center;
    align-self: end;
    width: 100%;
    margin-top: 8px;
  }

  .assist-controls button {
    align-self: center;
    min-height: 42px;
    height: 42px;
    padding: 9px 10px;
  }

  .assist-output {
    min-height: 0;
    margin-bottom: 0;
    font-size: 0.8rem;
    overflow: hidden;
  }

  .neighbor-grid {
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

  .neighbor-grid.win-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .win-panel {
    align-content: center;
    min-height: 0;
    height: 100%;
    padding: 22px 16px;
  }

  .win-panel h2 {
    font-size: clamp(1.65rem, 8vw, 2.5rem);
  }

  .win-word {
    font-size: clamp(2rem, 12vw, 3.5rem);
  }

  .neighbor {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    height: 100%;
    padding: 7px 8px;
    overflow: hidden;
    font-size: clamp(0.86rem, 3.45vw, 1rem);
  }

  .neighbor span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .shell {
    width: min(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px), 980px);
    max-width: 100%;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  .topbar {
    grid-row: 1;
    grid-column: 1;
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .wordmark {
    font-size: 1.12rem;
  }

  button {
    min-height: 34px;
  }

  #newGameButton {
    min-width: 0;
    min-height: 32px;
    padding: 6px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  #howToButton {
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    font-size: 0.92rem;
  }

  .status {
    grid-row: 1;
    grid-column: 1;
    align-self: center;
    position: relative;
    z-index: 1;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 0;
    pointer-events: none;
    text-align: center;
  }

  .target-prompt {
    font-size: 0.9rem;
    line-height: 0.95;
  }

  .status strong {
    font-size: 1.78rem;
    line-height: 0.95;
    overflow-wrap: anywhere;
  }

  .word-nav {
    grid-row: 2;
    margin: -2px 0 -3px;
  }

  .path {
    min-height: 0;
    margin: 0;
    padding: 0;
    font-size: 0.76rem;
    overflow-x: auto;
    overflow-y: clip;
    white-space: nowrap;
  }

  .path-word {
    font-size: 0.82rem;
    line-height: 1;
  }

  .path-word.current {
    font-size: 0.82rem;
    line-height: 1;
    margin-bottom: 0;
    max-width: min(32vw, 280px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .word-nav-actions {
    display: contents;
  }

  .move-count {
    font-size: 1.14rem;
  }

  .undo-button {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 0.78rem;
  }

  .play-area {
    grid-row: 3;
    min-height: 0;
    min-width: 0;
    display: grid;
    grid-template-rows: 0 minmax(0, 1fr) auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .play-area.win {
    grid-template-rows: minmax(0, 1fr);
  }

  .assist-output {
    min-height: 0;
    margin: 0;
    overflow: hidden;
  }

  .neighbor-grid {
    min-height: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .neighbor-grid.win-layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .neighbor {
    min-height: 0;
    height: 100%;
    padding: 6px 8px;
    overflow: hidden;
    font-size: 0.84rem;
  }

  .neighbor span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .assist-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-self: end;
    width: 100%;
    margin-top: 6px;
    gap: 6px;
  }

  .assist-controls button {
    align-self: center;
    height: 34px;
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .win-panel {
    align-content: center;
    min-height: 0;
    height: 100%;
    padding: 18px 16px;
  }

  .win-panel h2 {
    font-size: 1.65rem;
  }

  .win-word {
    font-size: 2.35rem;
  }

  .win-summary {
    font-size: 0.95rem;
  }

  .win-details,
  .win-copy,
  .win-new-game {
    min-width: 132px;
    min-height: 34px;
    padding: 7px 12px;
  }

  .details-dialog {
    width: min(640px, calc(100vw - 44px));
    max-height: calc(100dvh - 24px);
  }

  .details-head {
    padding: 12px 16px;
  }

  .details-content {
    max-height: calc(100dvh - 138px);
    padding: 14px 16px;
  }

  .details-foot {
    padding: 12px 16px;
  }
}
