:root {
  --color-primary: #ce0f69;
  --color-secondary-teal: #009ca6;
  --color-secondary-purple: #68478d;
  --color-tertiary-gold: #ffb81c;
  --color-tertiary-black: #000000;
}

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

/* Several elements set `display` via a class, which would otherwise beat
   the UA [hidden] rule and keep them visible while "hidden". */
[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: var(--color-tertiary-black);
}

.page {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  border-top: 6px solid transparent;
  border-image: linear-gradient(
    90deg,
    var(--color-primary),
    var(--color-secondary-teal),
    var(--color-secondary-purple),
    var(--color-tertiary-gold)
  );
  border-image-slice: 1;
}

h1 {
  font-size: 1.5rem;
  margin-bottom: -12px;
}

.subtitle {
  font-size: 0.9rem;
  color: #6b7280;
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
}

.loading {
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
}

/* ---------- HUD ---------- */

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  margin-bottom: 24px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-stat-center { align-items: center; }
.hud-stat-right { align-items: flex-end; }

.hud-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.swap-dots {
  display: flex;
  gap: 6px;
  height: 1.4rem;
  align-items: center;
}

.swap-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-secondary-purple);
}

.swap-dot.used {
  background: #e5e7eb;
}

/* ---------- Current rung ---------- */

.rung-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.drag-hint {
  font-size: 0.78rem;
  color: #6b7280;
}

.tiles {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
  /* stop touch drags on the tiles from scrolling the page */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tile {
  position: relative;
  flex: 1 1 0;
  max-width: 44px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--color-primary);
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: grab;
  transition: transform 0.15s ease;
}

.tile.dragging {
  z-index: 1;
  cursor: grabbing;
  transition: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.tile:focus-visible {
  outline: 2px solid var(--color-secondary-purple);
  outline-offset: 2px;
}

.tile-new {
  background: var(--color-tertiary-gold);
  color: var(--color-tertiary-black);
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chip-found {
  background: rgba(0, 156, 166, 0.12);
  color: #00737a;
}

.banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(104, 71, 141, 0.08);
  color: var(--color-secondary-purple);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ---------- Input ---------- */

.input-row {
  display: flex;
  gap: 10px;
}

.input-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 0 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(206, 15, 105, 0.12);
}

#wordInput {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: none;
  outline: none;
  padding: 12px 0;
  font-size: 1.1rem;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-tertiary-black);
  background: transparent;
}

#wordInput::placeholder {
  text-transform: none;
  letter-spacing: normal;
  color: #9ca3af;
}

.feedback {
  min-height: 1.5em;
  margin: 8px 0 4px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.feedback.good {
  color: #00737a;
  font-weight: 600;
}

.feedback.error {
  color: var(--color-primary);
}

.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--color-primary);
  color: #ffffff;
  transition: filter 0.15s ease;
}

.btn-primary:hover { filter: brightness(0.92); }
.btn-purple { background: var(--color-secondary-purple); }

.btn-secondary {
  width: 100%;
  margin-top: 24px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  background: #ffffff;
  color: #374151;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-secondary:hover,
.btn-secondary.armed {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.btn-text {
  border: none;
  background: none;
  padding: 4px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6b7280;
}

.btn-text:hover { color: var(--color-tertiary-black); }

button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Swap offer ---------- */

.swap-offer {
  margin: 8px 0 12px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(104, 71, 141, 0.08);
  font-size: 0.9rem;
  line-height: 1.45;
  color: #374151;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

/* ---------- Rung values, side words, ladder ---------- */

.values {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 20px;
  padding: 14px 16px;
  border-radius: 10px;
  background: #f9fafb;
  font-size: 0.85rem;
  color: #374151;
}

.values {
  gap: 10px;
  line-height: 1.45;
}

.values strong {
  color: var(--color-primary);
  white-space: nowrap;
}

.values .value-title {
  font-weight: 700;
  color: var(--color-tertiary-black);
}

.values .value-cost {
  color: var(--color-secondary-purple);
}

.side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.side-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.ladder-wrap .eyebrow {
  margin-bottom: 8px;
}

.ladder {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ladder-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: #f9fafb;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.ladder-row.current {
  box-shadow: inset 3px 0 0 var(--color-primary);
}

.ladder-word {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ladder-meta {
  color: #6b7280;
}

.ladder-points {
  font-weight: 600;
  min-width: 3.5em;
  text-align: right;
}

.tag {
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
  background: #f0f1f3;
  color: #6b7280;
}

.tag-swap {
  background: rgba(104, 71, 141, 0.12);
  color: var(--color-secondary-purple);
}

/* ---------- Summary ---------- */

.summary-title {
  font-size: 1.5rem;
  margin: 4px 0 6px;
}

.summary-intro {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #6b7280;
  margin-bottom: 20px;
}

.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.summary-stat {
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f9fafb;
}

.summary-stat.wide {
  grid-column: 1 / -1;
}

.btn-block {
  width: 100%;
  margin-top: 24px;
}

.best-today {
  margin-bottom: 18px;
  border-radius: 10px;
  background: rgba(0, 156, 166, 0.08);
  font-size: 0.85rem;
  color: #374151;
}

.best-today-summary {
  margin: 10px 0 0;
}

.best-today summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  padding: 10px 14px;
  text-align: center;
}

.best-today summary::-webkit-details-marker {
  display: none;
}

/* chevron, as on How to play, so it reads as tappable */
.best-today summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 2px solid #00737a;
  border-bottom: 2px solid #00737a;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s ease;
}

.best-today[open] summary::after {
  transform: rotate(-135deg) translateY(-2px);
}

.best-today summary:focus-visible {
  outline: 2px solid var(--color-secondary-teal);
  outline-offset: -2px;
  border-radius: 10px;
}

.best-today strong {
  color: #00737a;
  letter-spacing: 0.02em;
}

.best-stats {
  padding: 0 10px 10px;
}

.best-stats .summary-stat {
  background: #ffffff;
}

.save-section {
  margin-top: 16px;
}

.save-section .btn-secondary {
  margin-top: 8px;
}

.save-status {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #6b7280;
  text-align: center;
}

.save-status.success {
  color: #00737a;
  font-weight: 600;
}

.save-status.error {
  color: var(--color-primary);
  font-weight: 600;
}

.panel {
  margin-top: 12px;
  padding: 16px;
  border-radius: 10px;
  background: #f9fafb;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.panel-hint {
  font-size: 0.85rem;
  line-height: 1.4;
  color: #6b7280;
  margin-bottom: 12px;
}

.panel label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.text-input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 1rem; /* 16px stops iOS zooming into the field */
  color: var(--color-tertiary-black);
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(206, 15, 105, 0.12);
}

.form-error {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.summary-next {
  margin-top: 12px;
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
}

.summary-stat dt {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  margin-bottom: 4px;
}

.summary-stat dd {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- How to play ---------- */

.explainer {
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.explainer > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  font-weight: 600;
  font-size: 0.95rem;
}

.explainer > summary::-webkit-details-marker {
  display: none;
}

.explainer > summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.explainer > summary::after {
  content: "";
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-right: 2px solid #6b7280;
  border-bottom: 2px solid #6b7280;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.explainer[open] > summary::after {
  transform: rotate(-135deg);
}

.explainer[open] > summary {
  border-bottom: 1px solid #f0f1f3;
}

.explainer-content {
  padding: 4px 24px 24px;
}

.results-note {
  margin-top: 12px;
}

.results-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.result-day {
  border-radius: 10px;
  background: #f9fafb;
}

.result-day[open] {
  background: rgba(0, 156, 166, 0.08);
}

.result-day summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.result-day summary::-webkit-details-marker {
  display: none;
}

.result-day summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid #6b7280;
  border-bottom: 2px solid #6b7280;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s ease;
}

.result-day[open] summary::after {
  transform: rotate(-135deg) translateY(-2px);
}

.result-day summary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  border-radius: 10px;
}

.result-date {
  min-width: 5.5em;
  color: #6b7280;
}

.result-words {
  font-weight: 700;
  letter-spacing: 0.03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-points {
  font-weight: 700;
}

.results-more {
  margin-top: 10px;
}

.explainer-content h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  margin-top: 18px;
  margin-bottom: 6px;
}

.explainer-content p {
  font-size: 0.9rem;
  line-height: 1.55;
  color: #374151;
}

.explainer-content p + p {
  margin-top: 8px;
}

@media (max-width: 480px) {
  body { padding: 16px; }
  .card { padding: 22px 18px; }
  .tiles { gap: 3px; }
  .tile { font-size: 1.1rem; border-radius: 8px; }
}
