:root {
  --paper: #F7F5EE;
  --paper-line: #CBD6E4;
  --card: #FFFFFF;
  --ink: #1C2430;
  --ink-soft: #5B6472;
  --ink-faint: #9AA2AC;
  --red: #C6303E;
  --red-soft: #F6DEDF;
  --red-deep: #8C1E28;
  --amber: #B9791A;
  --amber-soft: #F6E6C9;
  --border: #DAD6C8;
  --border-strong: #C6C1AE;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(var(--paper) 0%, var(--paper) 100%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, var(--paper-line) 27px, var(--paper-line) 28px),
    repeating-linear-gradient(90deg, transparent, transparent 27px, var(--paper-line) 27px, var(--paper-line) 28px);
  background-blend-mode: normal;
  background-attachment: local;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', sans-serif;
  color: var(--ink);
  padding: 28px 16px 60px;
  -webkit-font-smoothing: antialiased;
  opacity: 0.02;
  transition: opacity .35s ease;
}

body.loaded {
  opacity: 1;
}

.wrap {
  max-width: 480px;
  margin: 0 auto;
}

.eyebrow {
  font-family: 'Space Grotesk', monospace;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--red);
  font-weight: 700;
  margin: 0 0 6px;
}

h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.stamp-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.subtitle {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
}

.stamp {
  flex-shrink: 0;
  border: 2.5px solid var(--red);
  color: var(--red);
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-9deg);
  font-family: 'Nanum Pen Script', cursive;
  font-size: 15px;
  line-height: 1.15;
  text-align: center;
  font-weight: 700;
  opacity: .85;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card h2 .num {
  font-family: 'Space Grotesk', monospace;
  color: var(--red);
  font-size: 13px;
}

label {
  font-size: 12px;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
}

input[type=text], input[type=number] {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #FCFBF7;
  color: var(--ink);
}

input[type=text]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.row > div {
  flex: 1;
  min-width: 140px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #F1EEE3;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 6px 5px 12px;
  font-size: 13px;
}

.chip button {
  border: none;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chip button:hover {
  background: var(--red-soft);
  color: var(--red-deep);
}

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.add-row input {
  flex: 1;
}

button.btn {
  border: 1px solid var(--border-strong);
  background: #FCFBF7;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

button.btn:hover {
  border-color: var(--ink-faint);
}

button.btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

button.btn.primary:hover {
  background: var(--red-deep);
  border-color: var(--red-deep);
}

button.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}

button.btn.ghost:hover {
  color: var(--red);
}

button.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 2px;
}

.tab {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-bottom: none;
  position: relative;
  top: 1px;
}

.tab.active {
  background: var(--card);
  color: var(--red-deep);
  border-color: var(--border);
}

.tab.new {
  color: var(--red);
  font-weight: 700;
}

.progress-track {
  height: 6px;
  background: #EDEAE0;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--red);
  border-radius: 4px;
  transition: width .3s ease;
}

table.sheet {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.sheet-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.sheet th, table.sheet td {
  border: 1px solid var(--border);
  padding: 0;
  text-align: center;
}

table.sheet thead th {
  background: #F1EEE3;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.sheet thead th.qcol {
  left: 0;
  z-index: 3;
}

table.sheet td.qnum {
  font-family: 'Space Grotesk', monospace;
  font-weight: 700;
  color: var(--ink-soft);
  background: #F1EEE3;
  position: sticky;
  left: 0;
  min-width: 44px;
  font-size: 12px;
}

table.sheet td.markcell {
  width: 56px;
  height: 44px;
  cursor: pointer;
  user-select: none;
  background: #FCFBF7;
}

table.sheet td.markcell:hover {
  background: #F1EEE3;
}

.mark {
  font-family: 'Nanum Pen Script', cursive;
  font-size: 28px;
  line-height: 1;
  display: inline-block;
}

.mark.o { color: var(--red); }
.mark.x { color: var(--red); }
.mark.blank {
  color: var(--border-strong);
  font-family: 'Space Grotesk', monospace;
  font-size: 11px;
}

th.member-th { min-width: 64px; }

.member-remove {
  display: block;
  font-size: 10px;
  color: var(--ink-faint);
  cursor: pointer;
  font-weight: 400;
  margin-top: 2px;
}

.member-remove:hover { color: var(--red); }

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.rank-item:last-child { border-bottom: none; }

.rank-badge {
  font-family: 'Space Grotesk', monospace;
  font-weight: 700;
  font-size: 12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amber-soft);
  color: var(--amber);
  flex-shrink: 0;
}

.rank-item:nth-child(1) .rank-badge { background: var(--red); color: #fff; }
.rank-item:nth-child(2) .rank-badge { background: var(--red-soft); color: var(--red-deep); }

.rank-body { flex: 1; min-width: 0; }
.rank-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.rank-pct { color: var(--red-deep); font-family: 'Space Grotesk', monospace; }
.rank-bar-track { height: 5px; background: #EDEAE0; border-radius: 3px; overflow: hidden; }
.rank-bar-fill { height: 100%; background: var(--red); border-radius: 3px; }
.rank-empty { color: var(--ink-faint); font-size: 13px; padding: 8px 0; }

.member-block { padding: 9px 0; border-bottom: 1px solid var(--border); }
.member-block:last-child { border-bottom: none; }
.member-name { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.member-substat { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-soft); margin-bottom: 4px; }
.member-substat:last-child { margin-bottom: 0; }
.member-substat .sub-label { width: 64px; flex-shrink: 0; }
.member-substat .bar-track { flex: 1; height: 5px; background: #EDEAE0; border-radius: 3px; overflow: hidden; }
.member-substat .bar-fill { height: 100%; background: #3B6D11; border-radius: 3px; }
.member-substat .bar-fill.alt { background: var(--amber); }
.member-substat .pct { width: 34px; text-align: right; font-family: 'Space Grotesk', monospace; font-size: 12px; color: var(--ink-soft); flex-shrink: 0; }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.empty-state { text-align: center; padding: 30px 10px; color: var(--ink-soft); font-size: 13px; }
.empty-state .big { font-family: 'Nanum Pen Script', cursive; font-size: 34px; color: var(--red); display: block; margin-bottom: 6px; }

.hint { font-size: 11px; color: var(--ink-faint); margin-top: 8px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-soft); margin-top: 10px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .mark { font-size: 16px; }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 12px;
  opacity: 0;
  transition: all .25s ease;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }