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

:root {
  --color-bg: #ffffff;
  --color-text: #1a1a1b;
  --color-text-secondary: #787c7e;
  --color-border: #d3d6da;
  --color-border-strong: #878a8c;
  --color-card-bg: #f6f7f8;
  --color-card-hover: #ebedf0;
  --color-selected-bg: #e8f0fe;
  --color-selected-border: #1a73e8;
  --color-green: #6aaa64;
  --color-yellow: #c9b458;
  --color-grey: #787c7e;
  --color-primary: #1a1a1b;
  --color-primary-hover: #3a3a3b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.14);
  --radius: 8px;
  --radius-sm: 4px;
  --max-width: 560px;
}

html, body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.slot {
  -webkit-tap-highlight-color: transparent;
  /* touch-action: pan-y keeps scroll on the slot body;
     only the .drag-handle uses touch-action: none */
  touch-action: pan-y;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding-bottom: 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.title-block {
  text-align: center;
  flex: 1;
}

.title-block h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.day-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 2px;
  font-weight: 600;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text);
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  flex-shrink: 0;
}

.streak {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  min-height: 32px;
  border-radius: var(--radius);
  background: var(--color-card-bg);
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.streak.hidden {
  display: none;
}

.streak-flame {
  font-size: 14px;
  line-height: 1;
}

.modal-streak {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.modal-streak.hidden {
  display: none;
}

.nav-btn:hover {
  background: var(--color-card-bg);
  border-color: var(--color-border-strong);
}

.prompt-section {
  text-align: center;
  margin-bottom: 20px;
  padding: 0 8px;
}

.prompt-section h2 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

.hint {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
  align-items: center;
}

.history-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 280px;
}

.history-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--color-grey);
}

.history-cell.green { background: var(--color-green); }
.history-cell.yellow { background: var(--color-yellow); }
.history-cell.grey { background: var(--color-grey); }

.board {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
  /* Reserve space before JS renders slots — prevents CLS on load */
  min-height: 432px;
  contain: layout;
}

.reveal-label {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
  text-align: center;
  font-weight: 600;
}

.slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  min-height: 48px;
  background: var(--color-card-bg);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
}

.slot:hover {
  background: var(--color-card-hover);
}

.slot:active {
  transform: scale(0.99);
}

.slot.selected {
  border-color: var(--color-selected-border);
  background: var(--color-selected-bg);
}

.slot-rank {
  font-weight: 700;
  font-size: 15px;
  color: var(--color-text-secondary);
  width: 22px;
  flex-shrink: 0;
  text-align: center;
}

.slot-label {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
}

.drag-handle {
  touch-action: none;
  cursor: grab;
  width: 24px;
  color: var(--color-border-strong);
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  margin: -4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.drag-handle:hover {
  color: var(--color-text);
}

.slot-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-left: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

.slot.green .slot-value,
.slot.yellow .slot-value,
.slot.grey-bg .slot-value {
  color: rgba(255, 255, 255, 0.9);
}

.source-note {
  font-size: 11px;
  color: var(--color-text-secondary);
  text-align: center;
  margin-top: 12px;
  font-style: italic;
}

.slot.revealed {
  cursor: default;
  background: var(--color-card-bg);
  touch-action: auto; /* re-enable scroll on revealed board */
}

.slot.revealed:hover {
  background: var(--color-card-bg);
}

.slot.green {
  background: var(--color-green);
  color: white;
  border-color: var(--color-green);
}

.slot.yellow {
  background: var(--color-yellow);
  color: white;
  border-color: var(--color-yellow);
}

.slot.grey-bg {
  background: var(--color-grey);
  color: white;
  border-color: var(--color-grey);
}

.slot.green .slot-rank,
.slot.yellow .slot-rank,
.slot.grey-bg .slot-rank {
  color: rgba(255, 255, 255, 0.85);
}

.controls {
  text-align: center;
  margin-bottom: 24px;
}

.guess-counter {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.button-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: var(--radius);
  padding: 12px 22px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-primary:disabled {
  background: var(--color-border);
  color: var(--color-text-secondary);
  cursor: not-allowed;
}

.btn-secondary {
  background: white;
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}

.btn-secondary:hover {
  background: var(--color-card-bg);
}

.btn-secondary:disabled {
  background: var(--color-card-bg);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
  cursor: not-allowed;
}

.tip {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 6px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h3 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

#modal-message {
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  font-size: 14px;
}

.modal-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--color-text);
}

.noscript-fallback {
  max-width: 600px;
  margin: 24px auto;
  padding: 24px;
  background: var(--color-card-bg);
  border-radius: var(--radius);
  text-align: left;
}

.noscript-fallback h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

.noscript-fallback p {
  margin-bottom: 12px;
  line-height: 1.55;
}

.modal-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 16px auto;
  align-items: center;
}

.modal-history .history-row {
  max-width: 180px;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.copied {
  margin-top: 12px;
  font-size: 13px;
  color: var(--color-green);
  min-height: 18px;
  font-weight: 600;
}

@media (max-width: 480px) {
  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .title-block h1 {
    font-size: 22px;
  }
  .slot-label {
    font-size: 14px;
  }
  .slot {
    padding: 11px 12px;
    min-height: 48px;
  }
  .history-row {
    max-width: 240px;
  }
  .prompt-section h2 {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .title-block h1 {
    font-size: 20px;
  }
  .slot-label {
    font-size: 13px;
  }
  .slot-rank {
    width: 18px;
    font-size: 14px;
  }
  .slot {
    gap: 8px;
    padding: 10px 10px;
  }
  .history-row {
    max-width: 200px;
  }
  .btn-primary, .btn-secondary {
    padding: 12px 16px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Drag-and-drop ─────────────────────────────────────────────────── */

/* Ghost element that follows the finger/cursor while dragging */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 500;
  opacity: 0.9;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  border-color: var(--color-selected-border) !important;
  background: var(--color-selected-bg) !important;
  transform: rotate(1.5deg) scale(1.03);
  transition: none !important;
  will-change: left, top;
  cursor: grabbing;
}

.drag-ghost .slot-rank {
  color: var(--color-selected-border) !important;
}

/* Slot being dragged — dims in place */
.slot.dragging {
  opacity: 0.35;
  border-color: var(--color-border) !important;
  background: var(--color-card-bg) !important;
  transition: opacity 0.1s;
}

/* Insert position indicator line */
.insert-indicator {
  height: 3px;
  background: var(--color-selected-border);
  border-radius: 2px;
  margin: 0 4px;
  pointer-events: none;
  flex-shrink: 0;
}

/* ── How to play overlay ───────────────────────────────────────────── */

.howto-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

.howto-overlay.hidden {
  display: none;
}

.howto-card {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: slideUp 0.25s ease-out;
}

.howto-card h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

.howto-intro {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 18px;
  color: var(--color-text);
}

.howto-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  text-align: left;
  background: var(--color-card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.howto-legend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: 1.3;
}

.howto-dot {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.howto-green  { background: var(--color-green); }
.howto-yellow { background: var(--color-yellow); }
.howto-grey   { background: var(--color-grey); }

.howto-tip {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
  line-height: 1.45;
}

.howto-play-btn {
  width: 100%;
  font-size: 15px;
  padding: 14px;
  margin-bottom: 10px;
}

.howto-new {
  font-size: 12px;
  color: var(--color-text-secondary);
}

@media (prefers-color-scheme: dark) {
  .howto-card {
    background: #272729;
    color: #d7dadc;
  }
  .howto-legend {
    background: #1a1a1b;
  }
}
