:root {
  --bg: #453a7d;
  --bg-deep: #362d66;
  --ink: #0d0d12;
  --muted: #6a6a78;
  --line: #3a3a3f;
  --green: #b6d7a8;
  --green-deep: #7fb36b;
  --red: #c0392b;
  --accent: #6b55e0;
  --shadow: 0 3px 5px rgba(0, 0, 0, 0.28);
  --font: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg-deep); }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1100px 650px at 50% -8%, #5b4ea1 0%, var(--bg) 55%, var(--bg-deep) 100%) fixed;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
body.lock { overflow: hidden; }

.stage {
  max-width: 780px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 32px) clamp(10px, 3vw, 24px) 8px;
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 3vw, 28px);
}
.foot { text-align: center; color: rgba(255, 255, 255, 0.55); font-size: 13px; padding: 14px 0 22px; letter-spacing: 0.04em; }

/* ---------- 카드 ---------- */
.card {
  position: relative;
  background: #fff;
  border: 2px solid #3d3d3d;
  border-radius: clamp(36px, 9vw, 96px);
  padding: clamp(18px, 4vw, 30px) clamp(16px, 3.6vw, 30px) clamp(22px, 4vw, 32px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
.stage.enter .card { animation: rise 0.4s ease both; }
.stage.enter .card:nth-child(2) { animation-delay: 0.06s; }
.head { position: relative; display: flex; align-items: center; justify-content: center; min-height: clamp(54px, 10vw, 78px); }
.title { margin: 0; font-size: clamp(34px, 7vw, 52px); font-weight: 800; letter-spacing: -0.02em; }
.edit-btn {
  position: absolute; right: clamp(0px, 1vw, 8px); top: 50%; transform: translateY(-50%);
  padding: 8px 26px; font-size: clamp(14px, 2.4vw, 17px);
}
.edit-btn:active { transform: translateY(calc(-50% + 1px)); }
.question { margin: 4px 0 0; text-align: center; font-size: clamp(16px, 2.8vw, 19px); color: #333; }

.meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; margin: 8px 0 clamp(12px, 3vw, 20px); font-size: 14px; color: var(--muted); }
.meta .tag { padding: 3px 12px; border-radius: 999px; background: #f1eefb; color: #4a3f8a; font-weight: 500; }
.meta .tag.done { background: #e4f1dc; color: #2f6a1b; }
.meta .tag.warn { background: #fdecea; color: var(--red); }

/* ---------- 알약 버튼 ---------- */
.pill {
  appearance: none; font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.12s, background 0.15s, box-shadow 0.12s, border-color 0.15s;
}
.pill:hover { box-shadow: 0 5px 9px rgba(0, 0, 0, 0.28); }
.pill:active { transform: translateY(1px) scale(0.992); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.pill:focus-visible, .btn:focus-visible, .tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.pill.on { background: var(--green); }
.pill:disabled { cursor: not-allowed; opacity: 0.55; box-shadow: none; }

/* ---------- 투표 항목 ---------- */
.opts { display: flex; flex-direction: column; gap: clamp(10px, 2.2vw, 18px); }
.opt {
  position: relative; overflow: hidden; width: 100%;
  display: flex; align-items: center; justify-content: center;
  height: clamp(58px, 11vw, 78px); padding: 0 clamp(64px, 14vw, 100px);
  font-size: clamp(17px, 3vw, 21px);
}
.opt .bar { position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); background: rgba(69, 58, 125, 0.11); transition: width 0.4s ease; }
.opt.on .bar { background: rgba(255, 255, 255, 0.35); }
.opt .lbl { position: relative; text-align: center; overflow-wrap: anywhere; line-height: 1.25; }
.opt .cnt { position: absolute; right: clamp(16px, 4vw, 32px); font-size: 14px; color: #55555f; font-variant-numeric: tabular-nums; }
.opt.win { border-width: 2px; font-weight: 700; }
.opt.win .cnt { color: #2f6a1b; font-weight: 700; }
.opt.locked { cursor: default; }
.opt.locked:hover, .opt.locked:active { box-shadow: var(--shadow); transform: none; }
.result { margin: clamp(12px, 3vw, 18px) 0 0; text-align: center; font-size: clamp(15px, 2.6vw, 18px); font-weight: 700; color: #2f6a1b; }
.result.none { color: var(--muted); font-weight: 500; }

/* ---------- 공지 ---------- */
.body {
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: keep-all;
  font-size: clamp(17px, 3vw, 21px); line-height: 1.65;
  padding: 6px clamp(6px, 2vw, 16px) 0; min-height: clamp(110px, 22vw, 180px);
}
.body a { color: #4a35c9; text-underline-offset: 3px; }
.confirm {
  display: block; margin: clamp(14px, 3vw, 22px) auto 0; padding: 0.3em 1.7em;
  font-size: clamp(26px, 5vw, 36px); font-weight: 800; border: 3px solid #444;
}

/* ---------- 부원 칩 ---------- */
.hint { margin: clamp(18px, 4vw, 30px) 0 10px; text-align: center; font-size: 14px; color: var(--muted); }
.hint.pulse { color: #4a35c9; font-weight: 700; animation: blink 1.1s ease-in-out infinite; }
.members { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(8px, 2vw, 14px); }
.members.attn .mem:not(.on) { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(107, 85, 224, 0.28), var(--shadow); }
.mem {
  height: clamp(46px, 8vw, 60px); padding: 0 10px; font-size: clamp(15px, 2.6vw, 19px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mem .tick { margin-right: 5px; font-weight: 800; color: #2f6a1b; }
.empty-msg { text-align: center; color: var(--muted); line-height: 1.7; padding: 20px 0 6px; }

/* ---------- 모달 ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(22, 16, 52, 0.58); backdrop-filter: blur(3px); animation: fade 0.15s ease;
  overflow-y: auto;
}
.dialog {
  position: relative; width: min(490px, 100%); background: #fff; border: 2px solid #3d3d3d;
  border-radius: clamp(34px, 8vw, 64px); padding: clamp(28px, 6vw, 42px) 24px clamp(26px, 6vw, 36px);
  text-align: center; box-shadow: 0 22px 54px rgba(0, 0, 0, 0.45); animation: pop 0.18s ease;
}
.dialog .x { position: absolute; top: 14px; right: 20px; width: 38px; height: 38px; font-size: 20px; line-height: 1; padding: 0; }
.dialog .who { font-size: clamp(26px, 5vw, 34px); font-weight: 700; }
.dialog .sub { margin-top: 6px; font-size: 15px; color: var(--muted); }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.choices .pill { padding: 7px 18px; font-size: 16px; }
.slots { position: relative; display: flex; justify-content: center; gap: clamp(10px, 3vw, 22px); margin: clamp(30px, 8vw, 56px) 0 6px; }
.slot {
  width: clamp(48px, 12vw, 66px); height: clamp(44px, 10vw, 56px); border-bottom: 6px solid #000; border-radius: 2px;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; font-size: 30px; line-height: 1;
  transition: border-color 0.15s;
}
.slot.cur { border-color: var(--accent); animation: blinkbar 1s steps(2, jump-none) infinite; }
.pin-input { position: absolute; inset: -12px; width: calc(100% + 24px); height: calc(100% + 24px); opacity: 0; font-size: 16px; border: 0; cursor: text; }
.pin-msg { min-height: 24px; margin: 14px 0 0; font-size: 15px; color: var(--red); }
.admin-field { margin: 24px 0 4px; }
.admin-field input { text-align: center; font-size: 18px; padding: 14px 18px; border-radius: 999px; }
.pin-hint { margin: 0; font-size: 13px; color: var(--muted); }
.dialog.busy .slots { opacity: 0.5; }
.shake { animation: shake 0.38s; }

/* ---------- 관리 시트 ---------- */
.sheet {
  position: relative; width: min(720px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
  background: #fff; border: 2px solid #3d3d3d; border-radius: clamp(28px, 6vw, 48px);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.45); animation: pop 0.18s ease; overflow: hidden;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: clamp(16px, 3vw, 22px) clamp(18px, 4vw, 30px) 6px; }
.sheet-head h2 { margin: 0; font-size: clamp(20px, 3.6vw, 26px); }
.sheet-head .sub { color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 8px; padding: 8px clamp(18px, 4vw, 30px) 12px; }
.tab { flex: 1; padding: 9px 0; font-size: 16px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 4px clamp(18px, 4vw, 30px) clamp(22px, 4vw, 30px); }

.field { margin-bottom: 18px; }
.field > label, .field > .lab { display: block; margin: 0 0 6px 4px; font-size: 14px; font-weight: 700; color: #333; }
.field .note { margin: 6px 4px 0; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="datetime-local"], textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
}
textarea { resize: vertical; min-height: 130px; line-height: 1.55; }
input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(107, 85, 224, 0.5); outline-offset: 1px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.btn {
  appearance: none; font: inherit; font-size: 15px; font-weight: 600; padding: 9px 20px; cursor: pointer;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  transition: transform 0.12s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--green); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.sm { padding: 5px 13px; font-size: 13px; box-shadow: none; }
.btn.tog.on { background: var(--green); border-color: var(--green-deep); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 4px 4px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: #6b55e0; }
.divider { height: 1px; background: #e4e1ee; margin: 22px 0; border: 0; }
.sheet h3 { margin: 0 0 10px 4px; font-size: 17px; }
.opt-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; margin-bottom: 8px; align-items: center; }
.opt-row .btn { padding: 8px 12px; min-width: 38px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; padding: 4px 12px; border-radius: 999px; border: 1px solid #c9c6d6; font-size: 14px; background: #fafafa; }
.chip.done { background: #e4f1dc; border-color: var(--green-deep); }
.chip small { color: #5a5a66; }
.mrow { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid #ece9f5; }
.mrow:last-of-type { border-bottom: 0; }
.mrow .acts { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 600px) { .mrow .acts { grid-column: 1 / -1; } }
.mrow input[type="text"] { padding: 8px 14px; }
.pwlist { display: grid; gap: 8px; margin: 16px 0 6px; text-align: left; }
.pwitem { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 18px; border: 1px solid var(--line); border-radius: 999px; }
.pwitem .nm { font-weight: 600; }
.pwitem code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 22px; font-weight: 700; letter-spacing: 0.18em; margin: 0 10px; }
.warn-box { margin: 0 0 4px; padding: 10px 14px; border-radius: 16px; background: #fff6e0; color: #7a5200; font-size: 14px; line-height: 1.5; text-align: left; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: min(92vw, 460px);
  padding: 12px 22px; border-radius: 999px; background: #1d1738; color: #fff; font-size: 15px; text-align: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #8e2b20; }

/* ---------- 애니메이션 ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes blink { 50% { opacity: 0.45; } }
@keyframes blinkbar { 50% { border-color: #cfc8f5; } }
.opts.shake .opt { animation: shake 0.38s; }

@media (max-width: 600px) {
  .members { grid-template-columns: repeat(3, 1fr); }
  .edit-btn { padding: 6px 18px; }
  .opt-row { grid-template-columns: 1fr auto auto auto; }
}
@media (max-width: 340px) { .members { grid-template-columns: repeat(2, 1fr); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- 멤버 화면 ---------- */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 20px 14px; padding: 10px 6px 0; }
.mwrap { position: relative; }
.mchip {
  width: 100%; min-height: 96px; padding: 12px 8px; border-radius: 38px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 18px;
}
.mchip .mn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mchip .mp { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 18px; font-weight: 600; letter-spacing: 0.14em; }
.mchip .mp.unset { color: #777; font-weight: 400; }
.mdel {
  position: absolute; top: -10px; right: -6px; width: 36px; height: 36px; padding: 0; border: 0; background: none;
  color: #d01616; font-size: 26px; font-weight: 900; line-height: 1; cursor: pointer; text-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}
.mdel:hover { color: #a50f0f; }
.mdel:focus-visible { outline: 3px solid var(--accent); border-radius: 50%; }
.mcaption { margin: 26px 0 0; text-align: center; font-size: clamp(15px, 2.6vw, 19px); color: #666; }
.add-plus {
  display: block; margin: 8px auto 0; padding: 0 22px; border: 0; background: none; cursor: pointer;
  font-size: 84px; line-height: 1.1; font-weight: 300; color: #9d9d9d; text-shadow: 0 3px 4px rgba(0, 0, 0, 0.3); transition: color 0.15s, transform 0.12s;
}
.add-plus:hover { color: #7d7d7d; }
.add-plus:active { transform: scale(0.94); }
.add-plus:focus-visible { outline: 3px solid var(--accent); border-radius: 18px; }
.pw-input { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 22px !important; font-weight: 700; letter-spacing: 0.3em; text-align: center; }
.pw-input::placeholder { font-size: 14px; letter-spacing: 0; font-weight: 400; }
