:root {
  --bg: #fff7f0;
  --bg2: #ffeede;
  --card: #ffffff;
  --ink: #4a3b34;
  --muted: #9a8a80;
  --line: #f1e3d8;
  --primary: #ff8a65;
  --primary-d: #f4511e;
  --mint: #7fd6c2;
  --sky: #8ec5ff;
  --lemon: #ffe08a;
  --lav: #c9b6ff;
  --stamp: #e53935;
  --radius: 20px;
  --shadow: 0 6px 20px rgba(160, 100, 70, .12);
  --font-title: 'Jua', 'Gowun Dodum', system-ui, sans-serif;
  --font: 'Gowun Dodum', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #ffe3d3 0, transparent 40%),
    radial-gradient(circle at 100% 30%, #e3f6ff 0, transparent 35%),
    radial-gradient(circle at 0% 100%, #f1e8ff 0, transparent 40%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-title); font-weight: normal; margin: 0; }
a { color: var(--primary-d); }

.loading { display: grid; place-items: center; min-height: 100vh; font-size: 64px; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; position: sticky; top: 0; z-index: 10;
  background: rgba(255, 247, 240, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .avatar { font-size: 30px; }
.topbar .who { flex: 1; min-width: 0; }
.topbar .who b { font-family: var(--font-title); font-size: 20px; display: block; }
.topbar .who small { color: var(--muted); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 140px; border: 0; background: none; padding: 6px 4px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; color: var(--muted);
  position: relative;
}
.tabs button .ic { font-size: 22px; filter: grayscale(.7); transition: transform .2s; }
.tabs button .lb { font-size: 12px; }
.tabs button.on { color: var(--primary-d); background: #fff1ea; }
.tabs button.on .ic { filter: none; transform: scale(1.15); }
.badge {
  position: absolute; top: 2px; right: calc(50% - 22px);
  background: var(--stamp); color: #fff; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px;
  padding: 0 5px; border-radius: 9px; text-align: center;
}

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { font-size: 22px; margin-bottom: 12px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 4px 10px; }
.section-title h2 { font-size: 22px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.empty .big { font-size: 48px; display: block; margin-bottom: 8px; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin: 0 0 6px 4px; }
.input {
  width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: #fffdfb;
  outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--primary); }
.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; cursor: pointer; font-weight: bold;
  background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-d);
  transition: transform .08s, box-shadow .08s; white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--primary-d); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 11px; box-shadow: 0 3px 0 var(--primary-d); }
.btn.ghost { background: #fff3ec; color: var(--primary-d); box-shadow: 0 3px 0 #f6d5c5; }
.btn.mint { background: var(--mint); box-shadow: 0 4px 0 #4fb8a2; }
.btn.gray { background: #eee6e0; color: var(--ink); box-shadow: 0 3px 0 #d8ccc3; }
.btn.danger { background: #ff6b6b; box-shadow: 0 3px 0 #d84848; }
.icon-btn { border: 0; background: #fff3ec; border-radius: 12px; padding: 8px 10px; cursor: pointer; font-size: 18px; }
.err { color: #d84848; font-size: 14px; min-height: 20px; margin: 4px 4px 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 14px;
}
.chip.on, .chip:active { border-color: var(--primary); background: #fff1ea; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.auth .logo { font-size: 72px; text-align: center; line-height: 1; margin-bottom: 8px; animation: bob 2.4s ease-in-out infinite; }
.auth h1 { text-align: center; font-size: 30px; margin-bottom: 4px; }
.auth p.sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }

/* ---------- stamp board ---------- */
.board-card {
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, #fbeee4 31px 32px),
    #fffdf8;
  border: 3px dashed #f3d2bf;
}
.board-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 14px; }
.board-head h2 { margin: 0; }
.board-count { font-family: var(--font-title); font-size: 30px; color: var(--primary-d); }
.board-count small { font-size: 18px; color: var(--muted); }
.board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
}
.slot {
  aspect-ratio: 1; border-radius: 50%; border: 3px dashed #f0cdb8; background: #fff;
  display: grid; place-items: center; position: relative; cursor: default;
  font-family: var(--font-title); color: #f0cdb8; font-size: clamp(14px, 4vw, 22px);
  padding: 0;
}
.slot.filled { border: 0; background: transparent; cursor: pointer; }
.slot.last::after {
  content: '🎁'; position: absolute; right: -6px; bottom: -6px; font-size: 18px;
}
.stamp {
  width: 100%; height: 100%; border-radius: 50%;
  border: 3px solid var(--stamp); color: var(--stamp);
  display: grid; place-items: center; text-align: center;
  font-family: var(--font-title); line-height: 1.05;
  font-size: clamp(10px, 2.6vw, 15px);
  transform: rotate(var(--rot, -12deg));
  background: radial-gradient(circle, rgba(229, 57, 53, .06), rgba(229, 57, 53, .12));
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px var(--stamp);
  opacity: .9;
  -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 60%, rgba(0,0,0,.75) 100%);
          mask-image: radial-gradient(circle at 30% 40%, #000 60%, rgba(0,0,0,.75) 100%);
}
.stamp.new { animation: thump .45s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes thump {
  0% { transform: scale(2.2) rotate(-30deg); opacity: 0; }
  60% { transform: scale(.9) rotate(var(--rot, -12deg)); opacity: 1; }
  100% { transform: scale(1) rotate(var(--rot, -12deg)); opacity: .9; }
}
.progress { height: 12px; border-radius: 6px; background: #f6e6dc; overflow: hidden; margin-top: 16px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--lemon), var(--primary)); border-radius: 6px; transition: width .5s; }
.board-msg { text-align: center; margin-top: 10px; color: var(--muted); }

/* ---------- coupons ---------- */
.coupon {
  display: flex; border-radius: 18px; overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow);
  background: linear-gradient(135deg, #fff3c4, #ffd9c2);
  position: relative;
}
.coupon.requested { background: linear-gradient(135deg, #e3f6ff, #d7e9ff); }
.coupon.used { background: #f1ece8; filter: grayscale(.9); opacity: .75; }
.coupon .left {
  width: 92px; display: grid; place-items: center; font-size: 40px;
  border-right: 3px dashed rgba(255, 255, 255, .9); position: relative;
}
.coupon .left::before, .coupon .left::after {
  content: ''; position: absolute; right: -11px; width: 20px; height: 20px; border-radius: 50%; background: var(--bg);
}
.coupon .left::before { top: -10px; }
.coupon .left::after { bottom: -10px; }
.coupon .body { flex: 1; padding: 14px 14px 12px; min-width: 0; }
.coupon .title { font-family: var(--font-title); font-size: 20px; word-break: keep-all; }
.coupon .code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; font-size: 13px; color: #8a6d5c; }
.coupon .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.coupon .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.coupon .used-mark {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%) rotate(-18deg);
  border: 3px solid #9a8a80; color: #9a8a80; border-radius: 10px; padding: 2px 10px;
  font-family: var(--font-title); font-size: 22px;
}
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #fff; }
.pill.req { background: var(--sky); color: #fff; }
.pill.act { background: var(--primary); color: #fff; }
.pill.used { background: #bbb; color: #fff; }

.seg { display: flex; background: #f6ebe3; border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 11px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.06); font-weight: bold; }

/* ---------- history ---------- */
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px dashed var(--line); }
.hist li:last-child { border-bottom: 0; }
.hist .dot { font-size: 22px; }
.hist .when { font-size: 12px; color: var(--muted); }
.date-sep { font-size: 13px; color: var(--muted); margin: 14px 4px 2px; font-weight: bold; }

/* ---------- admin ---------- */
.user-card { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.user-card .avatar { font-size: 40px; width: 56px; height: 56px; display: grid; place-items: center; background: var(--bg2); border-radius: 18px; }
.user-card .name { font-family: var(--font-title); font-size: 20px; }
.mini-board { display: flex; gap: 3px; margin-top: 6px; }
.mini-board i { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed #f0cdb8; }
.mini-board i.f { background: var(--stamp); border: 0; opacity: .85; }
.stamp-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer; font-size: 30px;
  background: radial-gradient(circle at 35% 30%, #ff8a80, var(--stamp)); color: #fff;
  box-shadow: 0 5px 0 #b71c1c; flex-shrink: 0;
  transition: transform .08s, box-shadow .08s;
}
.stamp-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b71c1c; }
.stamp-btn.big { width: 96px; height: 96px; font-size: 44px; }

.pending {
  background: linear-gradient(135deg, #e3f6ff, #eef0ff); border: 2px solid #cfe3ff;
}
.pending .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed #cfe3ff; }
.pending .item:last-child { border-bottom: 0; }

.back { border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--muted); padding: 4px 0; margin-bottom: 8px; }
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.detail-head .avatar { font-size: 48px; }
.detail-head h1 { font-size: 28px; }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-bottom: 12px; }
.emoji-grid button { border: 2px solid transparent; background: #fff8f3; border-radius: 10px; font-size: 22px; padding: 4px 0; cursor: pointer; }
.emoji-grid button.on { border-color: var(--primary); background: #fff1ea; }

.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.list-row:last-child { border-bottom: 0; }

/* ---------- modal / toast ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(74, 59, 52, .35); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s;
}
@media (min-width: 600px) { .modal-bg { align-items: center; } }
.modal {
  background: #fff; width: 100%; max-width: 440px; border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow: auto; animation: up .2s ease-out;
}
@media (min-width: 600px) { .modal { border-radius: 24px; } }
.modal h2 { font-size: 24px; margin-bottom: 14px; }
.modal .btns { display: flex; gap: 8px; margin-top: 16px; }
.modal .btns .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(74, 59, 52, .92); color: #fff; padding: 12px 18px; border-radius: 14px; z-index: 100;
  max-width: calc(100% - 32px); text-align: center; animation: up .2s;
}

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 200; width: 100%; height: 100%; }

.celebrate { text-align: center; }
.celebrate .big { font-size: 80px; animation: bob 1.4s ease-in-out infinite; }
.celebrate h2 { font-size: 28px; margin: 8px 0; }
