:root {
  color-scheme: dark;
  --bg: #080b10;
  --surface: #0f1623;
  --surface2: #141c2a;
  --ink: #f4f7fb;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.18);
  --song: #2dd4bf;
  --song-dim: rgba(45, 212, 191, 0.15);
  --rj: #fb7185;
  --rj-dim: rgba(251, 113, 133, 0.15);
  --danger: #fb7185;
  --warn: #fbbf24;
  --ok: #34d399;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button {
  cursor: pointer;
  font: inherit;
}

input {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(45, 212, 191, 0.1) 0%, transparent 34%),
    linear-gradient(225deg, rgba(251, 113, 133, 0.1) 0%, transparent 34%),
    var(--bg);
}

/* Header */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 10px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: rgba(8, 11, 16, 0.9);
  backdrop-filter: blur(16px);
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex: 0 0 auto;
  transition: background 0.3s;
}

.sync-dot.loading { background: var(--warn); }
.sync-dot.ok { background: var(--ok); }
.sync-dot.error { background: var(--danger); }

.hdr-btn {
  min-width: 40px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  padding: 0 8px;
}

.hdr-btn.danger {
  color: var(--danger);
}

/* Tab content */
.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Bottom nav */
.bottom-nav {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--border);
  background: rgba(8, 11, 16, 0.94);
  backdrop-filter: blur(16px);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 60px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  transition: color 0.15s;
  padding: 8px 0;
}

.nav-btn.active {
  color: var(--ink);
}

.nav-btn.record-nav.active {
  color: var(--song);
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-plus {
  font-size: 28px;
  font-weight: 300;
}

/* ── 현황 tab ── */
.status-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.person-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface);
}

.person-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--song);
}

.person-card.rj::before {
  background: var(--rj);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.person-mark-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.person-mark {
  width: 10px;
  height: 38px;
  border-radius: 4px;
  background: var(--song);
  box-shadow: 0 0 16px rgba(45, 212, 191, 0.4);
  flex: 0 0 auto;
}

.person-card.rj .person-mark {
  background: var(--rj);
  box-shadow: 0 0 16px rgba(251, 113, 133, 0.4);
}

.person-card h2 {
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 900;
  line-height: 1;
  min-width: 0;
}

.last-date {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  padding: 12px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.5);
  border: 1px solid var(--border);
}

.stat span {
  display: block;
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat strong {
  display: block;
  font-size: clamp(15px, 4.5vw, 20px);
  font-weight: 900;
  line-height: 1.1;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface);
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.summary-row > div {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.summary-row span {
  font-size: 11px;
  font-weight: 750;
  color: var(--muted);
}

.summary-row strong {
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 950;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-height: 1.3;
}

/* 현황 탭 - 룰 박스 */
.status-rules-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.status-rules-box summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.status-rules-box summary::-webkit-details-marker {
  display: none;
}

.status-rules-title {
  font-size: 15px;
  font-weight: 900;
}

.status-rules-box summary::after {
  content: '▸';
  font-size: 13px;
  color: var(--muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.status-rules-box[open] summary::after {
  transform: rotate(90deg);
}

.status-rules-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px 14px;
}

.status-rule-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.4);
}

.status-rule-item strong {
  display: block;
  font-size: 13px;
  font-weight: 900;
  margin-bottom: 5px;
}

.status-rule-item p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

/* ── 기록 tab ── */
.person-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(2, 6, 23, 0.5);
  margin-bottom: 22px;
}

.person-tab {
  height: 54px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  font-weight: 900;
  transition: all 0.15s;
}

.person-tab.active[data-person-tab="Song"] {
  background: var(--song);
  color: #03100d;
}

.person-tab.active[data-person-tab="RJ"] {
  background: var(--rj);
  color: #19070a;
}

.record-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  width: 100%;
}

.form-group > label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}

.form-group input[type="date"],
.form-group input[type="number"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 54px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 17px 14px;
  line-height: 1;
  background: rgba(7, 10, 16, 0.8);
  color: var(--ink);
  font-size: 17px;
  outline: none;
  box-sizing: border-box;
  vertical-align: middle;
}

.form-group input:focus {
  border-color: var(--song);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.15);
}

.record-form[data-active-person="RJ"] .form-group input:focus {
  border-color: var(--rj);
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.15);
}

.weight-row {
  display: grid;
  grid-template-columns: 54px 1fr 54px;
  gap: 8px;
}

.adj-btn {
  height: 54px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--ink);
  font-size: 26px;
  font-weight: 700;
}

.photo-label {
  display: block;
  cursor: pointer;
}

.photo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 54px;
  border: 1.5px dashed rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  color: var(--muted);
  transition: all 0.15s;
  padding: 0 16px;
  text-align: center;
}

.photo-btn.has-photo {
  border-style: solid;
  border-color: var(--ok);
  color: var(--ok);
}

.ocr-msg {
  min-height: 18px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.ocr-msg.ok { color: var(--ok); }
.ocr-msg.warn { color: var(--warn); }

.submit-btn {
  height: 58px;
  border: 0;
  border-radius: 14px;
  background: var(--song);
  color: #03100d;
  font-size: 17px;
  font-weight: 900;
  margin-top: 4px;
  transition: opacity 0.15s;
}

.submit-btn:active {
  opacity: 0.8;
}

.record-form[data-active-person="RJ"] .submit-btn {
  background: var(--rj);
  color: #19070a;
}

/* ── 주간 tab ── */
.rules-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 14px;
}

.rules-box summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  list-style: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
}

.rules-box summary::-webkit-details-marker {
  display: none;
}

.pill {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  color: var(--muted);
}

.rules-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px 14px;
}

.rules-grid div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.4);
}

.rules-grid strong {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
}

.rules-grid p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.final-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.final-box > div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.final-box span {
  display: block;
  font-size: 11px;
  font-weight: 750;
  color: var(--muted);
  margin-bottom: 6px;
}

.final-box strong {
  display: block;
  font-size: clamp(12px, 3.2vw, 16px);
  font-weight: 950;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-height: 1.3;
}

.weekly-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  border: 1px dashed rgba(148, 163, 184, 0.24);
  border-radius: 12px;
  font-size: 15px;
}

.weekly-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.weekly-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface);
}

.weekly-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.week-label {
  font-size: 14px;
  font-weight: 850;
  color: var(--muted);
}

.week-badge {
  min-height: 28px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 950;
  background: rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}

.weekly-card[data-result="Song"] .week-badge { background: var(--song); color: #03100d; }
.weekly-card[data-result="RJ"] .week-badge { background: var(--rj); color: #19070a; }
.weekly-card[data-result="무승부"] .week-badge { background: var(--warn); color: #1b1302; }
.weekly-card[data-result="진행 중"] .week-badge { background: #93c5fd; color: #07111f; }

.week-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.week-metrics > div {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.8);
}

.week-metrics span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 750;
  margin-bottom: 4px;
}

.week-metrics strong {
  display: block;
  font-size: 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.week-pot {
  font-size: 14px;
  color: var(--muted);
  font-weight: 850;
}

/* ── 로그 tab ── */
.log-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.5);
}

.log-filter {
  flex: 1;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
}

.log-filter.active {
  background: rgba(30, 41, 59, 0.98);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.log-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  border: 1px dashed rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  margin-bottom: 14px;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.log-item {
  display: grid;
  grid-template-columns: 1fr minmax(0, max-content) 42px 38px;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
  min-height: 64px;
}

.log-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.log-person-mark {
  width: 6px;
  height: 34px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.log-item[data-person="Song"] .log-person-mark { background: var(--song); }
.log-item[data-person="RJ"] .log-person-mark { background: var(--rj); }

.log-date {
  display: block;
  font-size: 14px;
  color: var(--muted);
  font-weight: 750;
}

.log-person-name {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 850;
  margin-top: 2px;
}

.log-weight {
  font-size: clamp(16px, 4.8vw, 22px);
  font-weight: 950;
  white-space: nowrap;
  text-align: right;
}

.log-photo-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.1);
  background-size: cover;
  background-position: center;
}

.log-photo-btn.no-photo {
  opacity: 0.22;
  pointer-events: none;
}

.log-del-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: rgba(251, 113, 133, 0.12);
  color: var(--danger);
  font-size: 22px;
  line-height: 1;
}

/* Photo section */
.photo-details {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.photo-details summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  list-style: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
}

.photo-details summary::-webkit-details-marker {
  display: none;
}

.photo-count-badge {
  min-width: 28px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 13px;
  font-weight: 900;
}

.photo-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 14px 14px;
}

.photo-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  background: rgba(148, 163, 184, 0.1);
  padding: 0;
  display: block;
  width: 100%;
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 5px 6px;
  background: rgba(0, 0, 0, 0.64);
  font-size: 11px;
  font-weight: 900;
  text-align: center;
  color: #fff;
}

/* Dialog */
dialog {
  width: min(92vw, 600px);
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: #05070b;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
}

dialog img {
  display: block;
  width: 100%;
  max-height: 85dvh;
  object-fit: contain;
  border-radius: 14px;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.64);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  display: grid;
  place-items: center;
}

/* ── Hints & Tooltips ────────────────────────────────────────────────────── */

.tab-hint {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
  line-height: 1.5;
  padding: 8px 12px;
  background: rgba(148, 163, 184, 0.07);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.field-hint {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(148, 163, 184, 0.65);
}

.card-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Tooltip */
[data-tip] {
  position: relative;
}

[data-tip]::before,
[data-tip]::after {
  pointer-events: none;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 20;
}

[data-tip]::before {
  content: '';
  bottom: calc(100% + 3px);
  border: 5px solid transparent;
  border-top-color: rgba(20, 28, 42, 0.97);
}

[data-tip]::after {
  content: attr(data-tip);
  bottom: calc(100% + 13px);
  background: rgba(20, 28, 42, 0.97);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: normal;
  text-align: center;
  width: 150px;
  line-height: 1.4;
}

[data-tip]:hover::before,
[data-tip]:hover::after,
[data-tip].tip-show::before,
[data-tip].tip-show::after {
  opacity: 1;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Desktop: center + limit width */
@media (min-width: 481px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
