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

:root {
  --bg:          #111113;
  --surface:     #1c1c1f;
  --surface-2:   #28282c;
  --border:      #3d3d42;
  --text:        #f4f4f5;
  --subtext:     #8c8c99;
  --accent:      #f97316;
  --accent-dim:  rgba(249, 115, 22, 0.14);
  --accent-border: rgba(249, 115, 22, 0.35);
  --green:       #22c55e;
  --green-bg:    rgba(34, 197, 94, 0.12);
  --yellow:      #eab308;
  --yellow-bg:   rgba(234, 179, 8, 0.12);
  --red:         #ef4444;
  --red-bg:      rgba(239, 68, 68, 0.12);
  --radius:      12px;
}

html { font-size: 16px; }

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

/* ── Header ─────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  max-width: 540px;
  margin: 0 auto;
  width: 100%;
  gap: 12px;
}

h1 {
  flex: 1;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1;
}

.title-stu { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.puzzle-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--subtext);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.help-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--subtext);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.help-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Main ───────────────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── State messages ─────────────────────────────────────────────── */
.state-msg {
  text-align: center;
  color: var(--subtext);
  padding: 60px 20px;
}

.hidden { display: none !important; }

/* ── Game screen layout ─────────────────────────────────────────── */
#game-screen {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.game-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  text-align: center;
}

.game-title {
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.item-list { margin-bottom: 24px; }

/* ── Category badge ─────────────────────────────────────────────── */
.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  white-space: nowrap;
}

.badge-emoji {
  font-size: 1rem;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Draggable list ─────────────────────────────────────────────── */
.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: rank-num;
}

.item-list li {
  counter-increment: rank-num;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px 10px 12px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.item-list li:active { cursor: grabbing; }

/* Auto rank number via CSS counter */
.item-list li::before {
  content: counter(rank-num);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.item-thumb {
  width: 62px;
  height: 62px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
}

.item-thumb--sm {
  width: 42px;
  height: 42px;
  border-radius: 6px;
}

.item-thumb--emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.item-thumb--sm.item-thumb--emoji {
  font-size: 1.5rem;
  border-radius: 6px;
}

.item-thumb--empty {
  background: transparent;
}

.item-label {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.drag-handle {
  color: var(--border);
  font-size: 1.15rem;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s;
}

.item-list li:hover .drag-handle { color: var(--subtext); }

/* SortableJS states */
.sortable-ghost {
  opacity: 0;
}

.sortable-chosen {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  border-color: var(--accent);
  background: var(--surface-2);
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}

.btn:active { transform: scale(0.98); }

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

.btn-share {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-share:hover { background: var(--border); }

/* ── Result screen ──────────────────────────────────────────────── */
#result-screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.4s ease;
}

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

.result-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  padding: 12px 0 4px;
}

.result-title {
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.result-title-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--subtext);
  display: block;
}

.result-title-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: block;
}

.emoji-row { font-size: 2rem; letter-spacing: 4px; }

.result-score { font-size: 0.82rem; color: var(--subtext); }

/* ── Answer reveal ──────────────────────────────────────────────── */
.answer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}


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

.answer-cols-header {
  display: grid;
  grid-template-columns: 44px 42px 1fr 44px;
  gap: 10px;
  padding: 0 12px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtext);
  text-align: center;
}

.answer-item {
  display: grid;
  grid-template-columns: 44px 42px 1fr 44px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  animation: slideIn 0.3s ease both;
}

.answer-item:nth-child(1) { animation-delay: 0.05s; }
.answer-item:nth-child(2) { animation-delay: 0.10s; }
.answer-item:nth-child(3) { animation-delay: 0.15s; }
.answer-item:nth-child(4) { animation-delay: 0.20s; }
.answer-item:nth-child(5) { animation-delay: 0.25s; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.answer-item.green  { background: var(--green-bg);  border-color: var(--green); }
.answer-item.yellow { background: var(--yellow-bg); border-color: var(--yellow); }
.answer-item.red    { background: var(--red-bg);    border-color: var(--red); }

.answer-rank-stu,
.answer-rank-you {
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 36px;
}

.answer-rank-stu { color: var(--accent); }

.answer-rank-you.green  { color: var(--green); }
.answer-rank-you.yellow { color: var(--yellow); }
.answer-rank-you.red    { color: var(--red); }

.answer-text {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Share ──────────────────────────────────────────────────────── */
.share-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.share-toast {
  font-size: 0.82rem;
  color: var(--green);
  font-weight: 600;
}

.next-puzzle-text,
.countdown-text {
  text-align: center;
  font-size: 0.76rem;
  color: var(--subtext);
  padding-top: 2px;
}

/* ── Help Modal ─────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px 24px;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.2s ease;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--subtext);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  padding-right: 30px;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--subtext);
  line-height: 1.6;
}

.modal-scoring {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 10px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.score-row .emoji { font-size: 1.15rem; width: 24px; text-align: center; }
.score-row .label { color: var(--subtext); }

.modal-footer {
  font-size: 0.78rem;
  color: var(--subtext);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 380px) {
  h1 { font-size: 1.3rem; }
  .item-list li { padding: 8px 10px 8px 10px; gap: 10px; }
  .item-thumb { width: 52px; height: 52px; }
}
