/* ── Reset & variables ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

button {
  touch-action: none;
}

:root {
  --color-correct: #22c55e;
  --color-close:   #f97316;
  --color-wrong:   #ef4444;
  --color-neutral: #cbd5e1;

  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --accent:        #6366f1;
  --accent-dark:   #4f46e5;

  --radius:        12px;
  --shadow:        0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lift:   0 8px 24px rgba(0,0,0,.14);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Header ────────────────────────────────────────────────────── */
#game-header {
  padding: 20px 0 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#header-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

#daily-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

#date-label {
  font-size: 11px;
  color: var(--text-muted);
}

#category-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 99px;
  letter-spacing: .03em;
}

#task-text {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
  max-width: 340px;
}

#unit-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Sort list ─────────────────────────────────────────────────── */
#sort-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* CSS counters for position numbers */
  counter-reset: item-counter;
}

/* ── Sort item ─────────────────────────────────────────────────── */
.sort-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 14px;
  min-height: 62px;
  background: var(--surface);
  border: 2px solid var(--color-neutral);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  user-select: none;
  counter-increment: item-counter;
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
  will-change: transform;
}

/* Placeholder while dragging */
.sort-item.is-dragging {
  opacity: 0;
}

/* Position number via CSS counter — auto-updates as items move in DOM */
.sort-item__position {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 18px;
  text-align: center;
}

.sort-item__position::before {
  content: counter(item-counter);
}

/* Ghost lives outside #sort-list, so CSS counters don't work there.
   Use a data attribute set dynamically in JS instead. */
.drag-ghost .sort-item__position::before {
  content: attr(data-pos);
}

.sort-item__emoji {
  font-size: 30px;
  width: 42px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.sort-item__name {
  font-size: 16px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sort-item__value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
  flex-shrink: 0;
}

.drag-handle {
  background: none;
  border: none;
  padding: 10px 6px;
  cursor: grab;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  flex-shrink: 0;
  border-radius: 6px;
  transition: color .15s, background .15s;
}

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

.drag-handle:active {
  cursor: grabbing;
}

/* Swap target highlight */
.sort-item.swap-target {
  border-color: var(--accent);
  background: #ede9fe;
}

/* Feedback states */
.sort-item--correct {
  border-color: var(--color-correct);
  background: #f0fdf4;
}

.sort-item--close {
  border-color: var(--color-close);
  background: #fff7ed;
}

.sort-item--wrong {
  border-color: var(--color-wrong);
  background: #fef2f2;
}

/* Locked items (correct position confirmed) — not draggable */
.sort-item--locked {
  cursor: default;
}

/* ── Ghost (floating clone during drag) ────────────────────────── */
.drag-ghost {
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  opacity: .92;
  transform: scale(1.025) rotate(.5deg);
  border: 2px solid var(--color-neutral);
  background: var(--surface);
  pointer-events: none;
}

/* ── Check button ──────────────────────────────────────────────── */
#check-btn {
  margin-top: 8px;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background .15s, transform .1s, box-shadow .15s;
}

#check-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: var(--shadow-lift);
}

#check-btn:active:not(:disabled) {
  transform: scale(.98);
}

#check-btn:disabled {
  background: var(--color-neutral);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Attempt history ───────────────────────────────────────────── */
#attempt-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attempt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.attempt-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 32px;
}

.attempt-dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot--correct { background: var(--color-correct); }
.dot--close   { background: var(--color-close); }
.dot--wrong   { background: var(--color-wrong); }

/* ── Win banner ────────────────────────────────────────────────── */
#win-banner {
  background: var(--surface);
  border: 2px solid var(--color-correct);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop-in .3s cubic-bezier(.34, 1.56, .64, 1) both;
}

#win-banner.hidden,
#game-header.hidden,
#game-main.hidden,
#error.hidden,
#loading.hidden {
  display: none;
}

#loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Loading animation ─────────────────────────────────────────── */
.loading-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 60%;
  margin-bottom: 20px;
}

.loading-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 14px;
  min-height: 44px;
  border: 2px solid;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loading-item--correct { border-color: var(--color-correct); background: #f0fdf4; }
.loading-item--close   { border-color: var(--color-close);   background: #fff7ed; }
.loading-item--wrong   { border-color: var(--color-wrong);   background: #fef2f2; }

.loading-item__emoji {
  width: 32px;
  height: 22px;
  border-radius: 5px;
  background: rgba(0,0,0,.08);
  flex-shrink: 0;
}

.loading-item__bar {
  flex: 1;
  height: 12px;
  border-radius: 5px;
  background: rgba(0,0,0,.08);
  max-width: 60%;
}

.loading-text {
  color: var(--text-muted);
  font-size: 14px;
}

#error {
  text-align: center;
  padding: 48px 16px;
}

.error-message {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.error-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 220px;
  padding: 12px 22px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  touch-action: none;
  transition: background .15s, box-shadow .15s;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.btn--primary:hover {
  background: var(--accent-dark);
  box-shadow: var(--shadow-lift);
}

.btn--secondary {
  background: var(--surface);
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn--secondary:hover {
  background: #ede9fe;
}

@keyframes pop-in {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#win-stars {
  font-size: 36px;
  margin-bottom: 10px;
  letter-spacing: 4px;
}

#win-message {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

#win-sub {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Win sub link ──────────────────────────────────────────────── */
#win-sub a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

#win-sub a:hover {
  text-decoration: underline;
}

/* ── Source info icon button ───────────────────────────────────── */
.sort-item__source-btn {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  color: var(--color-neutral);
  border-radius: 4px;
  transition: color .15s;
}

.sort-item__source-btn:hover,
.sort-item__source-btn.is-active {
  color: var(--accent);
}

/* ── Source popover ────────────────────────────────────────────── */
#source-popover {
  position: fixed;
  background: var(--surface);
  border: 1.5px solid var(--color-neutral);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  padding: 10px 14px;
  min-width: 180px;
  max-width: 280px;
  z-index: 100;
  animation: pop-in .15s cubic-bezier(.34, 1.56, .64, 1) both;
}

#source-popover.hidden {
  display: none;
}

.source-popover__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.source-popover__link {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.source-popover__link:hover {
  text-decoration: underline;
}

/* ── Top nav (shared between pages) ───────────────────────────── */
.top-nav {
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 16px 0;
  display: flex;
  align-items: center;
  position: relative;
}

.top-nav__logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}

.top-nav__logo-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--text);
}

.top-nav__link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}

.top-nav__link:hover {
  color: var(--accent);
  background: #ede9fe;
}

/* ── Archive page shell ────────────────────────────────────────── */
#archive-app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Archive month header ──────────────────────────────────────── */
.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 4px;
}

.month-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.month-nav-btn {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}

.month-nav-btn:hover:not(:disabled) {
  color: var(--accent);
  background: #ede9fe;
}

.month-nav-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

/* ── Day list ──────────────────────────────────────────────────── */
.day-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Day row (shared base) ─────────────────────────────────────── */
.day-row {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.day-row--today {
  border-color: var(--accent);
}

.day-row--future {
  opacity: .55;
}

/* Clickable row — the <a> fills the whole row */
.day-row__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
}

.day-row__link:hover {
  background: #f8f7ff;
}

/* Future row — no link, same layout via direct children */
.day-row--future {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.day-row__weekday {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 30px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.day-row__date {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 60px;
  display: flex;
  align-items: center;
  gap: 6px;
}


.day-row__category,
.day-row__metric {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.day-row__category--badge {
  display: inline-block;
  flex: none;
  margin-right: auto;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 99px;
  letter-spacing: .03em;
}

.day-row__metric {
  text-align: right;
  flex: 0 0 auto;
}

.day-row__arrow {
  font-size: 20px;
  color: var(--text-muted);
  margin-left: 4px;
}

.day-row__lock {
  font-size: 16px;
  margin-left: auto;
}

/* ── Responsive tweaks ─────────────────────────────────────────── */
@media (max-width: 360px) {
  #task-text { font-size: 16px; }
  .sort-item__name { font-size: 14px; }
  .sort-item__emoji { font-size: 24px; width: 34px; }
}

/* ── Nav right slot ─────────────────────────────────────────────── */
.top-nav__link--right {
  margin-left: auto;
}

/* ── Feedback page ──────────────────────────────────────────────── */
#feedback-app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.feedback-header {
  padding: 20px 0 4px;
}

.feedback-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.feedback-sub {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Form fields ─────────────────────────────────────────────────── */
#feedback-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.form-label__optional {
  font-weight: 400;
  color: var(--text-muted);
}

.form-label__required {
  color: var(--color-wrong);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid var(--color-neutral);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color .15s;
  outline: none;
  box-sizing: border-box;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input--textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
}

.form-input.is-invalid {
  border-color: var(--color-wrong);
}

/* ── Star rating ─────────────────────────────────────────────────── */
.star-rating {
  display: flex;
  flex-direction: row-reverse;
  gap: 4px;
  width: fit-content;
}

.star-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.star-label {
  font-size: 28px;
  color: var(--color-neutral);
  cursor: pointer;
  transition: color .1s;
  line-height: 1;
}

.star-input:checked ~ .star-label,
.star-label:hover,
.star-label:hover ~ .star-label {
  color: #f59e0b;
}

/* ── Submit button ───────────────────────────────────────────────── */
.feedback-submit-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  margin-top: 4px;
}

.feedback-submit-btn:disabled {
  background: var(--color-neutral);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Hidden states ───────────────────────────────────────────────── */
#feedback-form.hidden,
#feedback-success.hidden,
#feedback-error.hidden {
  display: none;
}

/* ── Success state ───────────────────────────────────────────────── */
.feedback-success {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 2px solid var(--color-correct);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop-in .3s cubic-bezier(.34, 1.56, .64, 1) both;
}

.feedback-success__icon {
  font-size: 40px;
  color: var(--color-correct);
  font-weight: 700;
  margin-bottom: 12px;
}

.feedback-success__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.feedback-success__sub {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Error banner ────────────────────────────────────────────────── */
.feedback-error {
  font-size: 14px;
  color: var(--color-wrong);
  background: #fef2f2;
  border: 2px solid var(--color-wrong);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 500;
}
