@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@400;500;600;700&display=swap');

:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --ink: #2a2438;
  --muted: #7a7289;
  --border: #e9e2d9;
  --primary: #6d4aff;
  --primary-dark: #5634e0;
  --primary-soft: #efeaff;
  --accent: #ff8a5b;
  --danger: #d9434f;
  --danger-soft: #fdecee;
  --warn-soft: #fff5dd;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(42, 36, 56, 0.08);
  --tap: 52px;
  font-family: 'Prompt', system-ui, -apple-system, 'Segoe UI', 'Leelawadee UI', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body { background: var(--bg); color: var(--ink); min-height: 100vh; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 18px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-weight: 500; cursor: pointer; text-decoration: none; color: var(--ink);
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-lg { min-height: var(--tap); padding: 12px 36px; font-size: 1.1rem; font-weight: 600; }
.btn-sm { min-height: 36px; padding: 4px 14px; font-size: .9rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn-icon {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 1.1rem; flex: none;
}
.btn-icon:hover { border-color: var(--primary); }
.btn-icon:disabled { opacity: .35; cursor: default; }

.muted { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 100; font-size: .95rem; max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); }

/* ============================================================
   หน้าเล่น
   ============================================================ */
.player-shell {
  max-width: 560px; margin: 0 auto; padding: 24px 18px 48px;
  min-height: 100vh; display: flex; flex-direction: column;
}
.screen { flex: 1; display: flex; flex-direction: column; animation: fade-in .3s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.screen-center { justify-content: center; align-items: center; text-align: center; gap: 16px; }
.cover {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-badge {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  font-size: 3rem; background: var(--primary-soft);
}
.player h1 { font-size: 1.9rem; line-height: 1.3; font-weight: 700; }
.lead { font-size: 1.05rem; white-space: pre-line; }
.eyebrow { color: var(--primary); font-weight: 600; letter-spacing: .02em; }

.q-top { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.progress { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .35s ease; }
.q-count { font-size: .9rem; min-width: 3.2em; text-align: right; }
.q-image { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); margin-bottom: 20px; }
.q-text { font-size: 1.45rem; line-height: 1.4; font-weight: 600; margin-bottom: 22px; }

.choices { display: flex; flex-direction: column; gap: 12px; }
.choice {
  min-height: 60px; padding: 14px 20px; text-align: left;
  background: var(--surface); border: 2px solid var(--border); border-radius: 16px;
  font-size: 1.05rem; cursor: pointer; transition: border-color .15s, background .15s, transform .1s;
}
.choice:hover { border-color: var(--primary); }
.choice:active { transform: scale(.99); }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); font-weight: 500; }

.result-card {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 28px 22px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.result-card .cover { box-shadow: none; }
.result-card h1 { font-size: 2.1rem; color: var(--primary); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--primary-soft); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   หน้าแก้ไข
   ============================================================ */
.login-card {
  max-width: 380px; margin: 12vh auto 0; padding: 32px 26px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.4rem; margin-bottom: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.input, .textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); font-size: 1rem; color: var(--ink);
}
.textarea { min-height: 76px; resize: vertical; }
.input:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.error { color: var(--danger); font-size: .92rem; }

.editor-bar {
  position: sticky; top: 0; z-index: 10; background: rgba(251, 247, 242, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.editor-bar-inner {
  max-width: 880px; margin: 0 auto; padding: 10px 18px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
}
.editor-bar strong { font-size: 1.05rem; }
.save-status { font-size: .88rem; color: var(--muted); }
.save-status.dirty { color: #b86e00; }
.bar-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }

.editor-main { max-width: 880px; margin: 0 auto; padding: 20px 18px 80px; display: flex; flex-direction: column; gap: 20px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.panel h2 { font-size: 1.2rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: .9rem; margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.item { border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.item-head { display: flex; align-items: center; gap: 8px; }
.item-head .label { font-weight: 600; margin-right: auto; }
.item-num {
  display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .85rem; margin-right: 6px;
}

.image-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.image-field img { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.image-empty {
  width: 96px; height: 72px; border-radius: 10px; border: 1.5px dashed var(--border);
  display: grid; place-items: center; color: var(--muted); font-size: .8rem;
}

.choice-edit { background: #faf8fc; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.choice-row { display: flex; gap: 8px; align-items: center; }
.choice-row .input { flex: 1; }
.scores { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scores-label { font-size: .82rem; color: var(--muted); margin-right: 2px; }
.score {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 12px;
  border: 1.5px solid var(--border); border-radius: 999px; background: var(--surface); font-size: .88rem;
}
.score.on { border-color: var(--primary); background: var(--primary-soft); }
.score input {
  width: 52px; height: 30px; border: none; border-radius: 999px; text-align: center;
  background: var(--bg); font-size: .95rem;
}
.score input:focus { outline: 2px solid var(--primary); }

.warnings { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.warnings li { background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; font-size: .92rem; }
.warnings li.ok { background: #e8f7ee; }
.warnings li.bad { background: var(--danger-soft); }

@media (min-width: 768px) {
  .player-shell { padding-top: 48px; }
  .player h1 { font-size: 2.3rem; }
}
