/* =====================================================================
 * Theme mềm, ấm — lấy cảm hứng từ bìa album "3" của Ngọt
 * ===================================================================== */
:root {
  --bg: #f26b38;            /* cam của bìa album */
  --cream: #fffaf5;
  --paper: #ffffff;
  --ink: #4a3227;           /* nâu ấm thay cho đen */
  --muted: #9a7a68;
  --accent: #ee7a45;        /* cam dịu */
  --accent-deep: #d9622f;
  --accent-soft: #fde9dc;
  --line: #f2e5d9;
  --chip-bg: #fff8f2;
  --chip-b: #f3cfb6;
  --danger: #d0524a;
  --ok: #5e8c52;
  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;
  --shadow: 0 20px 44px -16px rgba(120, 45, 10, .38), 0 2px 8px rgba(120, 45, 10, .08);
  --shadow-sm: 0 2px 8px rgba(200, 110, 60, .14);
  font-family: 'Nunito', 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 40%, rgba(255, 240, 228, .10), rgba(150, 50, 10, .16) 85%),
    url("/pattern.svg");
  background-size: cover, 64px 64px;
  background-attachment: fixed, fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

.app {
  display: grid;
  grid-template-columns: minmax(340px, 440px) 1fr;
  gap: 24px;
  padding: 24px;
  height: 100vh;
}
.left { display: flex; flex-direction: column; gap: 20px; min-height: 0; }
.panel { background: var(--cream); border-radius: var(--r-lg); box-shadow: var(--shadow); }

/* ---------- title ---------- */
.title-card { padding: 24px 26px 20px; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .28em; color: var(--accent); text-transform: uppercase; }
.eyebrow.big { font-size: 14px; letter-spacing: .32em; }
h1 { margin: 6px 0 10px; font-size: clamp(30px, 2.8vw, 46px); overflow-wrap: anywhere; font-weight: 900; line-height: 1.02; letter-spacing: -.005em; color: var(--ink); }
.desc { margin: 0 0 16px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); line-height: 1.6; }
.progress { height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.bar { height: 100%; width: 0; background: linear-gradient(90deg, #f5a06b, var(--accent)); border-radius: 99px; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.progress-text { margin-top: 9px; font-size: 13px; font-weight: 800; color: var(--accent-deep); }
.session-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.link-btn { background: none; border: 0; padding: 0; cursor: pointer; font-weight: 700; color: var(--muted); text-align: left; }
.link-btn:hover { color: var(--accent-deep); text-decoration: underline; text-underline-offset: 3px; }
.save-state { white-space: nowrap; }
.save-state.err { color: var(--danger); }

/* ---------- draw card ---------- */
.draw-card { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px 20px; }
.draw-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.remaining { font-weight: 800; color: var(--accent-deep); font-size: 13px; background: var(--accent-soft); padding: 3px 10px; border-radius: 99px; }
.stage { flex: 1; min-height: 250px; border-radius: var(--r-md); position: relative; overflow: hidden; display: flex; transition: box-shadow .2s; }
.stage.empty { border: 2px dashed #f4c3a4; background: #fffdfb; align-items: center; justify-content: center; text-align: center; }
.stage.revealed, .stage.rolling {
  background: linear-gradient(150deg, #f59a66 0%, #ee7a45 55%, #e86c38 100%);
  color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}
.stage.drop-hover { box-shadow: inset 0 0 0 3px rgba(74, 50, 39, .5); }
.stage.nudge { animation: nudge .4s ease; }
@keyframes nudge { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.empty-msg { font-size: 19px; font-weight: 800; color: #b08670; padding: 20px; line-height: 1.45; }
.empty-msg b { color: var(--accent); }
.empty-msg small { display: block; font-size: 13px; font-weight: 600; margin-top: 6px; }

.reveal { display: flex; flex-direction: column; gap: 14px; padding: 20px; width: 100%; overflow: auto; cursor: grab; animation: pop .4s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
.reveal-top { display: flex; gap: 18px; align-items: center; }
.disc {
  width: 112px; height: 112px; flex: none; border-radius: 50%;
  background: repeating-radial-gradient(circle at 50% 50%, #3a2820 0 2px, #4a3429 2px 4px);
  display: grid; place-items: center;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, .9), 0 10px 24px rgba(90, 30, 5, .3);
  animation: spin 8s linear infinite;
}
.disc.playing { animation-duration: 2.4s; }
.rolling .disc { animation-duration: .5s; }
.disc-label { width: 48%; height: 48%; border-radius: 50%; background: #fff4ec; overflow: hidden; display: grid; place-items: center; position: relative; }
.disc-label img { width: 100%; height: 100%; object-fit: cover; }
.disc-label::after { content: ''; position: absolute; width: 16%; height: 16%; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 3px #fff4ec; }
@keyframes spin { to { transform: rotate(360deg); } }
.kicker { font-size: 12.5px; font-weight: 800; letter-spacing: .1em; opacity: .92; text-transform: uppercase; }
.song-title { font-size: clamp(26px, 2.3vw, 38px); font-weight: 900; line-height: 1.08; margin: 4px 0 2px; overflow-wrap: anywhere; text-shadow: 0 1px 12px rgba(150, 50, 10, .15); }
.song-sub { font-size: 13px; font-weight: 600; opacity: .9; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; background: rgba(255, 255, 255, .16); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(2px); }
.meta div { min-width: 0; }
.meta dt { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; opacity: .8; font-weight: 800; }
.meta dd { margin: 2px 0 0; font-weight: 700; font-size: 14.5px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; background: #fff; color: var(--accent-deep);
  border: 0; border-radius: 99px; padding: 9px 16px; font-weight: 800; font-size: 13px; text-decoration: none; cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.pill-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(120, 40, 5, .18); }
.pill-btn.apple { background: var(--ink); color: #fff7f1; }
.pill-btn.ghost { background: rgba(255, 255, 255, .2); color: #fff; }
.pill-btn.ghost:hover { background: rgba(255, 255, 255, .28); }
.pill-btn kbd { opacity: .55; }
.chip.removed { cursor: pointer; }
.apple-status { font-size: 11.5px; font-weight: 600; opacity: .9; }
.apple-status.warn { background: rgba(80, 25, 0, .15); padding: 6px 10px; border-radius: 10px; }
.rolling-wrap { display: flex; align-items: center; gap: 18px; padding: 20px; width: 100%; }
.roll-title { font-size: clamp(24px, 2.2vw, 34px); font-weight: 900; line-height: 1.1; }
.roll-kicker { font-size: 12.5px; font-weight: 800; letter-spacing: .12em; opacity: .85; }

.hint { font-size: 12px; color: var(--muted); margin: 12px 2px; line-height: 1.5; }
.controls { display: flex; flex-wrap: wrap; gap: 7px; }
.ctl {
  font-size: 13px; font-weight: 800; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 99px; padding: 8px 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.ctl:hover { border-color: var(--chip-b); transform: translateY(-1px); box-shadow: 0 6px 14px rgba(200, 110, 60, .18); }
.ctl:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.ctl.primary { background: linear-gradient(150deg, #f59a66, var(--accent)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px -4px rgba(217, 98, 47, .55); }
kbd { font: inherit; font-size: 10px; font-weight: 800; opacity: .5; }
.ctl.primary kbd { opacity: .85; }

/* ---------- board ---------- */
.board { padding: 18px; display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; }
.tiers { display: flex; flex-direction: column; gap: 12px; flex: 1 0 auto; }
.tier {
  display: grid; grid-template-columns: clamp(130px, 12vw, 200px) 1fr; gap: 6px; min-height: 84px; flex: 1 0 auto;
  border-radius: var(--r-md); padding: 6px; background: var(--paper); border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(200, 110, 60, .06);
}
.tier:last-child { flex-grow: 2; }
.tier-label {
  background: var(--c); color: var(--t); position: relative; border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 14px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}
.tier-num { position: absolute; top: 7px; left: 10px; font-size: 11px; font-weight: 800; opacity: .7; }
.tier-name { font-size: clamp(20px, 1.8vw, 28px); font-weight: 900; letter-spacing: .02em; line-height: 1.05; }
.tier-sub { font-size: 11.5px; font-weight: 700; margin-top: 6px; opacity: .9; line-height: 1.35; }
.tier-count { position: absolute; bottom: 7px; right: 10px; font-size: 10.5px; font-weight: 800; opacity: .65; }
.tier-cards { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 7px; padding: 6px; border-radius: 13px; transition: background .15s, box-shadow .15s; }
.tier-cards.drop-hover, .removed-zone.drop-hover { background: #fff4ec; box-shadow: inset 0 0 0 2px #f6b893; }

.chip {
  display: flex; flex-direction: column; padding: 6px 12px; background: var(--chip-bg);
  border: 1.5px solid var(--chip-b); border-radius: var(--r-sm); cursor: grab; max-width: 290px; user-select: none;
  box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.chip:hover { border-color: #efab83; transform: translateY(-1px); box-shadow: 0 6px 14px rgba(200, 110, 60, .2); }
.chip b { font-size: 13px; font-weight: 800; line-height: 1.25; }
.chip small { font-size: 10.5px; color: var(--muted); font-weight: 600; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.dragging { opacity: .3; }
.chip.flash { animation: flash 1.3s cubic-bezier(.2, .8, .2, 1); }
@keyframes flash { 0% { transform: scale(1.12); box-shadow: 0 0 0 6px rgba(238, 122, 69, .35); } 100% { transform: none; } }
.drop-marker { width: 4px; align-self: stretch; min-height: 30px; background: var(--accent); border-radius: 4px; }

.removed-zone {
  border: 1.5px dashed #ead7c8; border-radius: var(--r-md); padding: 9px 12px; display: flex; flex-wrap: wrap; gap: 7px;
  align-items: center; font-size: 12px; color: var(--muted); min-height: 46px; flex: none;
}
.removed-zone .label { font-weight: 800; letter-spacing: .14em; text-transform: uppercase; font-size: 11px; margin-right: 4px; }
.removed-zone .chip { border-color: #e6d8cc; opacity: .75; box-shadow: none; }

/* ---------- modal ---------- */
dialog {
  border: 0; border-radius: var(--r-lg); padding: 0; width: min(580px, 94vw); max-height: 88vh;
  background: var(--cream); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(90, 30, 5, .45); overflow: hidden;
}
dialog[open] { animation: dlgIn .25s cubic-bezier(.2, .8, .2, 1); }
@keyframes dlgIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
dialog.wide { width: min(1000px, 96vw); }
dialog::backdrop { background: rgba(74, 35, 15, .38); backdrop-filter: blur(4px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); margin: 0; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 900; }
.x:focus { outline: none; }
.x:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(238, 122, 69, .35); }
:focus-visible { outline: 2px solid #f2a77c; outline-offset: 2px; }
.x { border: 0; background: var(--accent-soft); width: 32px; height: 32px; border-radius: 50%; font-size: 14px; cursor: pointer; color: var(--accent-deep); }
.x:hover { background: #fbdcc8; }
.modal-body { padding: 18px 22px 22px; overflow: auto; max-height: calc(88vh - 70px); }
.muted { color: var(--muted); font-size: 12.5px; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-item { text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: 16px; padding: 13px 15px; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform .15s, border-color .15s; }
.menu-item:hover { border-color: var(--chip-b); transform: translateY(-1px); }
.menu-item b { display: block; font-size: 14px; }
.menu-item span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.menu-item.danger b { color: var(--danger); }

.btn { border: 1px solid var(--line); background: var(--paper); border-radius: 99px; padding: 7px 14px; font-weight: 700; font-size: 13px; cursor: pointer; transition: border-color .15s; }
.btn:hover { border-color: var(--chip-b); }
.btn.primary { background: linear-gradient(150deg, #f59a66, var(--accent)); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 11px; font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); position: sticky; top: -18px; background: var(--cream); }
tr.current td { background: #fff3ea; }
tr.skipped td { opacity: .6; }
tr.skipped td:last-child { opacity: 1; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 99px; background: var(--c, #f1e7df); color: var(--t, var(--ink)); white-space: nowrap; }
.warn-text { color: var(--danger); font-weight: 700; font-size: 11.5px; }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); }
.form label.full { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
input[type=text], input[type=number], input[type=url], input[type=search], input[type=password], textarea {
  font: inherit; font-size: 14px; color: var(--ink); padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper);
}
input:focus { outline: none; border-color: #f2a77c; box-shadow: 0 0 0 3px rgba(238, 122, 69, .18); }

.rules dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 12px; align-items: center; margin: 0 0 16px; }
.rules dt { margin: 0; }
.rules dd { margin: 0; font-size: 13px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; font-size: 13px; }
.keys kbd { opacity: 1; font-size: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; white-space: nowrap; justify-self: start; box-shadow: 0 1px 0 var(--line); }
.rules h3, .modal-body h3 { font-size: 12.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin: 4px 0 10px; }

.vote-song { font-size: 20px; font-weight: 900; text-align: center; }
.vote-timer { font-size: 54px; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1.1; margin: 4px 0 14px; }
.vote-timer.urgent { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.vote-cols { display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); gap: 9px; }
.vote-col { border: 0; background: var(--paper); border-radius: 16px; padding: 9px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: inset 0 0 0 1px var(--line), var(--shadow-sm); }
.vote-col.win { box-shadow: inset 0 0 0 2.5px var(--c), var(--shadow-sm); }
.vote-bar-wrap { width: 100%; height: 120px; background: #f8efe7; border-radius: 11px; display: flex; align-items: flex-end; overflow: hidden; }
.vote-bar { width: 100%; background: var(--c); border-radius: 11px 11px 0 0; transition: height .25s cubic-bezier(.2, .8, .2, 1); }
.vote-count { font-size: 24px; font-weight: 900; }
.vote-name { font-size: 11.5px; font-weight: 800; }
.vote-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.log-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.log-list li { padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; }
.log-list time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12px; }

/* ---------- sửa trực tiếp tại chỗ ---------- */
[data-edit] { cursor: text; border-radius: 8px; transition: background .15s, box-shadow .15s; }
[data-edit]:hover:not(.editing) { box-shadow: 0 0 0 4px rgba(238, 122, 69, .14); background: rgba(238, 122, 69, .08); }
.tier-label [data-edit]:hover:not(.editing) { box-shadow: 0 0 0 4px rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .14); }
[data-edit].editing { outline: none; background: rgba(255, 255, 255, .9); color: var(--ink); box-shadow: 0 0 0 3px rgba(238, 122, 69, .45); caret-color: var(--accent-deep); }
.tier-label [data-edit] { padding: 1px 6px; max-width: 100%; overflow-wrap: anywhere; }
.tier-label .tier-sub:empty::before { content: '+ mô tả'; opacity: .55; }
#desc:empty::before { content: '+ thêm mô tả'; opacity: .6; }
.tier-color-btn {
  position: absolute; top: 5px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .25); font-size: 13px; cursor: pointer; opacity: 0; transition: opacity .15s, background .15s;
}
.tier-label:hover .tier-color-btn, .tier-color-btn:focus-visible { opacity: 1; }
.tier-color-btn:hover { background: rgba(255, 255, 255, .45); }

/* ---------- sửa tiêu đề & các hạng ---------- */
textarea { resize: vertical; line-height: 1.5; }
.title-card, .tier-label { cursor: default; }
.tier-edit-list { display: flex; flex-direction: column; gap: 10px; }
.tier-edit { display: grid; grid-template-columns: 150px 1fr auto; gap: 14px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); padding: 8px; }
.tier-label.edit-preview { min-height: 86px; }
.tier-label.edit-preview .tier-name { font-size: 22px; }
.tier-edit-fields { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.tier-edit label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted); }
.tier-edit-color { align-items: center; }
input[type=color] { width: 46px; height: 40px; padding: 3px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); cursor: pointer; }
@media (max-width: 760px) { .tier-edit { grid-template-columns: 1fr; } .tier-edit-fields { grid-template-columns: 1fr; } }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; pointer-events: none; }
.toast { background: var(--ink); color: #fff7f1; padding: 10px 18px; border-radius: 99px; font-size: 13.5px; font-weight: 700; box-shadow: 0 12px 28px -8px rgba(60, 25, 5, .45); animation: toastIn .25s cubic-bezier(.2, .8, .2, 1); max-width: min(560px, 92vw); text-align: center; }
.toast.warn { background: #b8642f; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.toast.action { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 8px 10px 8px 18px; }
.toast.action button { border: 0; background: rgba(255, 255, 255, .16); color: #fff7f1; font-weight: 800; font-size: 12.5px; padding: 6px 12px; border-radius: 99px; cursor: pointer; }
.toast.action button:hover { background: rgba(255, 255, 255, .26); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; padding: 16px; gap: 16px; }
  .board { overflow: visible; }
  .tier { grid-template-columns: 110px 1fr; }
  .menu-grid, .form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .disc, .reveal, .chip.flash, dialog[open] { animation: none !important; }
}
