:root {
  --font-base: "Quicksand", sans-serif;
  --font-script: "Delius", sans-serif;
  --soft-brown: #a67c52;
  --gentle-beige: #d9c2a4;
  --warm-cream: #fff7e1;
  --dark-brown: #5c3b1e;
  --light-beige: #e5d2bc;
  --bg-start: #fff7e1;
  --bg-end: #eecc9b;
  --surface: rgba(255, 247, 225, 0.78);
  --text: #5c3b1e;
  --muted: #a67c52;
  --accent: #a67c52;
  --accent-strong: #5c3b1e;
  --border: rgba(92, 59, 30, 0.22);
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-base);
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  background-attachment: fixed;
  color: var(--text);
  text-align: center;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.topbar {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

h1 {
  grid-column: 2;
  justify-self: center;
  margin: 0;
  font-size: 1.5rem;
  font-family: var(--font-base);
  color: var(--dark-brown);
  font-weight: 700;
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
}



.step-home-link {
  font-family: "Noto Emoji", "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  text-decoration: none;
  font-size: 1.05rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-actions {
  grid-column: 3;
  justify-self: end;
  gap: 0.35rem;
}

h2 {
  margin-top: 0;
}

.start-subtitle {
  margin: 0.3rem auto 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03) inset, 0 2px 8px rgba(92, 59, 30, 0.08);
  backdrop-filter: blur(1px);
}

.controls {
  margin-top: 1rem;
  display: grid;
  gap: 0.8rem;
  max-width: 580px;
}

.control-group {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.control-group label {
  font-weight: 600;
  text-align: center;
  color: var(--soft-brown);
}

input {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.65rem;
  font-size: 0.95rem;
  min-width: 190px;
  text-align: center;
  text-transform: uppercase;
  font-family: var(--font-base);
  color: var(--dark-brown);
  background: rgba(255, 255, 255, 0.65);
}

input::placeholder {
  text-transform: uppercase;
}

.control-group.stacked {
  flex-direction: column;
  gap: 0.35rem;
}

button {
  border: 1px solid rgba(92, 59, 30, 0.35);
  border-radius: 999px;
  background: var(--accent);
  color: var(--warm-cream);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font-base);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.danger {
  background: var(--danger);
}

button.subtle {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(92, 59, 30, 0.25);
  padding: 0.25rem 0.45rem;
  font-size: 0.8rem;
}

button.subtle:hover {
  background: #eef2f5;
  color: var(--text);
}

.workspace {
  margin-top: 1rem;
}

.workspace[hidden],
.controls[hidden] {
  display: none;
}

.panel {
  max-width: 760px;
}

.builder-actions {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
  position: relative;
}

.workflow-nav {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 0.6rem;
}

.workflow-nav .subtle {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.3rem 0.75rem;
  margin-bottom: 0;
}

.workflow-nav .subtle:hover {
  background: transparent;
  color: var(--dark-brown);
}

.workflow-nav .subtle.active {
  background: transparent;
  color: var(--dark-brown);
  border-bottom-color: var(--soft-brown);
}

.icon-btn {
  min-width: 2rem;
}

.undo-btn {
  transform: rotate(180deg);
}

.builder-menu {
  margin: 0 auto 0.45rem;
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  flex-wrap: wrap;
}

.panel-sheet {
  margin: 0.45rem auto 0.55rem;
  padding: 0.65rem;
  border: 1px solid rgba(92, 59, 30, 0.22);
  border-radius: 10px;
  background: rgba(255, 247, 225, 0.55);
  max-width: 640px;
}

.panel-sheet h3 {
  margin: 0 0 0.5rem;
}

.sheet-list {
  display: grid;
  gap: 0.35rem;
}

#history-list {
  margin-top: 0.45rem;
  margin-bottom: 0.7rem;
  padding-left: 1.1rem;
}

.sheet-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  padding-right: 2rem;
}

.history-item {
  text-transform: uppercase;
  background: transparent;
  color: var(--dark-brown);
  border: none;
  border-radius: 0;
  font-weight: 500;
  text-align: left;
  padding: 0.24rem 0.1rem;
}

.history-item:hover {
  background: rgba(92, 59, 30, 0.07);
  color: var(--dark-brown);
}

.history-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 13.5rem;
  align-items: center;
  gap: 0.45rem;
}

.history-row .history-item {
  grid-column: 1;
  width: 100%;
}

.history-edited {
  grid-column: 2;
  justify-self: end;
  font-style: italic;
  opacity: 0.75;
  white-space: nowrap;
  text-align: right;
}

.history-empty {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0;
}

.history-foot {
  margin-top: 0.55rem;
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 0.35rem;
}

.history-clear-btn {
  font-size: 0.86rem;
  opacity: 0.78;
}

.history-delete-some-btn {
  font-size: 0.86rem;
  opacity: 0.78;
}

.history-clear-btn:hover {
  opacity: 1;
}

.history-delete-some-btn:hover {
  opacity: 1;
}

.history-clear-confirm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.history-storage-note {
  margin: 0;
  text-align: center;
}

.history-trash {
  position: absolute;
  left: -2rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: auto;
  transition: opacity 120ms ease;
  min-width: 1.75rem;
  padding: 0.2rem 0.2rem;
}

.history-row:hover .history-trash,
.history-row:focus-within .history-trash,
.history-trash:hover,
.history-trash:focus-visible {
  opacity: 1;
}

.clue-row {
  display: grid;
  gap: 0.25rem;
}

.clue-word {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.clue-row input {
  text-transform: none;
  font-style: italic;
  width: min(25ch, 100%);
  min-width: 0;
  margin: 0 auto;
}

.clue-row input::placeholder {
  text-transform: none;
  font-style: italic;
}

.clue-ghost {
  background: transparent;
  border: 1px dashed rgba(92, 59, 30, 0.2);
  color: rgba(92, 59, 30, 0.52);
  border-radius: 8px;
  text-align: center;
  padding: 0.42rem 0.55rem;
  font-style: italic;
  text-transform: none;
  font-weight: 500;
  width: min(25ch, 100%);
  margin: 0 auto;
}

.clue-ghost:hover {
  background: rgba(92, 59, 30, 0.05);
}

.clues-next-row {
  margin-top: 0.55rem;
  display: flex;
  justify-content: center;
}

.panel-sheet label {
  display: block;
  margin: 0.2rem 0;
}

.publish-option {
  display: grid !important;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-items: start;
  column-gap: 0.32rem;
  color: var(--dark-brown);
  font-weight: 500;
  width: 100%;
  max-width: none;
  margin: 0;
}

.publish-option input[type="checkbox"] {
  display: block;
  width: 1rem;
  height: 1rem;
  min-width: 0;
  padding: 0;
  border: none;
  accent-color: var(--soft-brown);
  margin: 0;
  align-self: start;
  justify-self: start;
}

.publish-option span {
  display: block;
  line-height: 1.25;
  text-align: left;
}

.publish-preview {
  margin: 0.5rem auto 0.6rem;
  background: #fff;
  border: 1px solid rgba(92, 59, 30, 0.18);
  border-radius: 8px;
  padding: 1.25rem 0.35rem 0.35rem;
  max-width: 520px;
}

.publish-title-wrap {
  margin: 0.2rem auto 0.55rem;
  max-width: 520px;
}

#publish-title-input {
  width: 100%;
  text-transform: none;
}

#publish-title-input::placeholder {
  text-transform: none;
  font-style: italic;
}

.publish-options-grid {
  display: grid;
  gap: 0.28rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  justify-items: start;
}

#clues-panel,
#publish-panel {
  border: none;
  background: transparent;
  box-shadow: none;
}

#history-panel {
  position: relative;
  border: none;
  background: transparent;
  box-shadow: none;
  max-width: 580px;
}

#history-close-btn {
  position: absolute;
  top: 0.15rem;
  right: 0.15rem;
}

#history-view .panel {
  max-width: 580px;
}

.publish-preview svg {
  width: 100%;
  height: auto;
  display: block;
}

.no-candidates {
  display: grid;
  justify-content: center;
  justify-items: center;
  gap: 0.35rem;
}

.no-candidates-actions {
  display: flex;
  justify-content: center;
}

.print-region {
  display: none;
}

.meta,
#status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.finish-helper {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(92, 59, 30, 0.22);
  border-radius: 10px;
  background: rgba(255, 247, 225, 0.45);
}

.finish-panel {
  margin-top: 0.45rem;
  padding: 0.45rem 0.55rem 0.35rem;
  border: 1px solid rgba(92, 59, 30, 0.16);
  border-radius: 10px;
  background: rgba(255, 247, 225, 0.45);
}

.finish-panel__head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.1rem;
}

.build-footer-actions {
  margin-top: 0.65rem;
  padding-top: 0.3rem;
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  align-items: center;
}

.finish-endword-dialog {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.finish-endword-dialog[hidden] {
  display: none !important;
}

.finish-endword-dialog label {
  color: var(--soft-brown);
  font-size: 0.88rem;
  font-weight: 600;
}

.finish-helper__path {
  margin: 0;
  font-size: 0.98rem;
  color: var(--dark-brown);
}

.finish-helper__info {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  color: var(--soft-brown);
}

.finish-helper__actions {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.finish-helper__meta {
  font-size: 0.75rem;
  color: var(--soft-brown);
  display: inline-block;
  min-width: 5ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.finish-helper__accept-row {
  margin-top: 0.35rem;
  display: flex;
  justify-content: center;
}

#status.error {
  color: var(--danger);
  font-weight: 600;
}

.ladder-list {
  margin: 0.8rem 0 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.35rem;
  justify-items: center;
}

.ladder-item {
  display: block;
  position: relative;
  width: max-content;
  margin: 0 auto;
  border-radius: 10px;
  padding: 0.05rem 0.2rem;
}

.ladder-item.active .ladder-word {
  font-weight: 700;
  color: var(--dark-brown);
}

.ladder-word {
  min-width: 5ch;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  text-align: center;
  font-size: 1.35rem;
}

.ladder-item.active {
  display: block;
}

.ladder-item.active .undo-btn {
  position: absolute;
  left: -2.3rem;
  top: 50%;
  transform: translateY(-50%) rotate(180deg);
}

.ladder-item.can-jump {
  cursor: pointer;
}

.jump-flag {
  position: absolute;
  left: calc(100% + 0.35rem);
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  padding: 0.2rem 0.46rem;
  background: #fff4c8;
  color: #6f4f2d;
  border: 1px solid rgba(92, 59, 30, 0.22);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.16s ease;
  white-space: nowrap;
}

.jump-flag::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 7px solid #fff4c8;
}

.ladder-item:hover .jump-flag,
.ladder-item:focus-within .jump-flag {
  opacity: 1;
  transform: translateY(-50%) translateX(1px);
}

.ladder-item:focus-visible {
  outline: 2px solid rgba(166, 124, 82, 0.45);
  outline-offset: 2px;
}

.candidate-groups {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.5rem;
}

.candidate-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(var(--col-count, 4), minmax(0, 1fr));
}

.candidate-col-title {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 0.05rem;
}

.candidate-letter {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--dark-brown);
}

.candidate-streak {
  font-size: 0.76rem;
  color: var(--soft-brown);
  font-family: "Georgia", "Times New Roman", serif;
  font-style: italic;
  letter-spacing: 0.04em;
  cursor: help;
}

.candidate-col {
  border: none;
  border-radius: 10px;
  padding: 0.45rem;
  display: grid;
  gap: 0.3rem;
  align-content: start;
  min-height: 40px;
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(92, 59, 30, 0.14);
}

.candidate-btn {
  text-transform: uppercase;
  color: var(--dark-brown);
  border: 1px solid rgba(92, 59, 30, 0.22);
  padding: 0.4rem 0.55rem;
  font-weight: 600;
}

.candidate-btn:hover {
  filter: brightness(0.97);
}

@media (max-width: 800px) {
  .app {
    padding-top: 0.75rem;
  }

  .control-group label {
    min-width: 100%;
  }

  input {
    width: 100%;
  }

  .workspace {
    margin-top: 0.5rem;
  }

  .panel {
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    padding: 0.3rem 0;
  }

  .builder-actions {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -0.25rem 0.45rem;
    padding: 0.4rem 0.25rem;
    background: transparent;
    border-bottom: none;
    backdrop-filter: none;
    isolation: isolate;
  }

  .builder-menu {
    margin-bottom: 0.35rem;
  }

  .builder-actions::before {
    content: "";
    position: absolute;
    top: -2px;
    bottom: -2px;
    left: 50%;
    width: 100vw;
    transform: translateX(-50%);
    z-index: -1;
    background: var(--bg-start);
    opacity: 0;
    transition: opacity 140ms ease;
  }

  .builder-actions.is-stuck::before {
    opacity: 1;
  }

  .candidate-grid {
    --mobile-col-width: 72%;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: var(--mobile-col-width);
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 0;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 0.45rem;
    gap: 0.7rem;
    mask-image: linear-gradient(to right, transparent 0, black 7%, black 93%, transparent 100%);
  }

  .candidate-grid::before,
  .candidate-grid::after {
    content: "";
    display: block;
    width: calc((100% - var(--mobile-col-width)) / 2);
  }

  .candidate-col {
    scroll-snap-align: center;
    scroll-snap-stop: always;
    min-height: 120px;
  }

  .candidate-btn {
    padding: 0.3rem 0.32rem;
    font-size: 0.82rem;
    margin-block: 0.14rem;
    min-height: 2.1rem;
  }

  #history-list {
    padding-left: 0.8rem;
  }

  .history-row {
    grid-template-columns: minmax(0, 1fr) 9.25rem;
    gap: 0.35rem;
  }

  #history-delete-some-btn {
    display: inline-block;
  }

  #history-panel:not(.history-delete-mode) .history-trash {
    opacity: 0;
    pointer-events: none;
  }

  #history-panel.history-delete-mode .history-trash {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (min-width: 801px) {
  #history-delete-some-btn {
    display: none !important;
  }
}

@media print {
  body * {
    visibility: hidden !important;
  }

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

  .print-region {
    display: block !important;
    position: absolute;
    inset: 0;
    background: #fff;
    padding: 0.3in;
  }

  .print-region svg {
    width: 100%;
    height: auto;
    display: block;
  }
}

