:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0da;
  --accent: #c8102e;
  --ok: #1a7f37;
  --bad: #b42318;
  --warn: #b54708;
  --chip: #f0eee9;
  --p1: #8a3ab9; /* 예매자 1 = 보라 */
  --p2: #2457c5; /* 예매자 2 = 파랑 */
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; }
button, select, input { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: var(--ink); }
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
button.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
button:disabled { opacity: .4; cursor: default; }
input, select { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: #fff; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 24px; align-items: center; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar h1 { font-size: 16px; margin: 0; }
#tabs { display: flex; gap: 4px; }
#tabs button { border: none; background: transparent; padding: 8px 12px; border-radius: 6px; }
#tabs button.active { background: var(--ink); color: #fff; }
.whoami { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.conn { font-size: 12px; color: var(--muted); }
.conn.on { color: var(--ok); }
.conn.off { color: var(--bad); }

main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.panel h3 { font-size: 14px; margin: 12px 0 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); }
.err { color: var(--bad); }
.hint { background: #fff8e6; border: 1px solid #f3dfae; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }

.p1 { color: var(--p1); }
.p2 { color: var(--p2); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--chip); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.tag.gv { background: #fde7ea; color: var(--accent); }
.tag.hedge { background: #fff1e0; color: var(--warn); }
.tag.must { background: var(--ink); color: #fff; }
.tag.want { background: #555; color: #fff; }
.tag.maybe { background: #ddd; color: #333; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 56px; background: var(--panel); }
tr.graded { background: #fcfbf8; }
/* 작품 목록: 행 사이를 넉넉하게 */
tbody td { padding: 14px 10px; }
.title-cell { line-height: 1.4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 12px; background: var(--chip); border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.chip-when { font-variant-numeric: tabular-nums; }
.chip-where { margin-left: 6px; color: var(--muted); }
.chip .tag { margin-left: 6px; }
/* 작품 목록의 회차 칩은 한 줄에 하나씩 */
tbody .chips { flex-direction: column; align-items: flex-start; }
.meta-cell { font-size: 13px; color: var(--muted); }
.chip.together { border-color: #9bb5ea; }
.chip.solo { border-style: dashed; border-color: #bbb; }
.chip.none { opacity: .35; }
.chip.excluded { text-decoration: line-through; opacity: .45; }
.chip.owned { background: #e3f2e7; border-color: var(--ok); opacity: 1; }
.grade-select { width: 104px; border-radius: 6px; transition: background-color .12s, color .12s; }
.grade-select.g-must { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }
.grade-select.g-want { background: #e4eafa; color: #23407f; border-color: #c2d0ef; font-weight: 600; }
.grade-select.g-maybe { background: #f2f0ea; color: #5f5c55; border-color: #e0ddd4; }
.grade-select.g-none { background: #fafafa; color: #a9a9ae; border-color: #ececed; }
.grade-select.g-unavailable { background: #f6f5f3; color: #a09a94; border-style: dashed; border-color: #ddd8d0; opacity: 1; }

.chip-legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.chip-legend .chip { cursor: default; }

.plan-list { counter-reset: step; list-style: none; margin: 0; padding: 0; }
.plan-list li { display: grid; grid-template-columns: 36px 90px 70px 1fr 220px; gap: 8px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plan-list li::before { counter-increment: step; content: counter(step); color: var(--muted); text-align: right; }
.code { font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: .5px; }

.live-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.big-card { background: var(--panel); border: 2px solid var(--ink); border-radius: 14px; padding: 24px; }
.big-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.big-card .big-code { font-size: 72px; line-height: 1; margin: 8px 0 12px; font-family: ui-monospace, Consolas, monospace; font-weight: 800; }
.big-card .title { font-size: 22px; font-weight: 700; }
.big-card .meta { font-size: 16px; margin: 6px 0 16px; }
.big-card .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.big-card .actions button { font-size: 18px; padding: 12px 22px; border-radius: 10px; }
.big-card.pending { border-color: var(--accent); }
.seats { font-size: 20px; font-weight: 800; color: var(--accent); }
.other-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.log li { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.log { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow: auto; }
.kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }

/* 작품 정보 모달 */
.film-link { color: #2457c5; text-decoration: underline; cursor: pointer; }
.film-title { font-weight: 700; }
.row-link { cursor: pointer; }
.tag.none { background: #eee; color: #888; }
.chip.keyword { background: #eef1f7; color: #3c4a68; cursor: default; }
.modal-overlay { position: fixed; inset: 0; background: rgba(20, 20, 22, .55); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100; }
.modal { position: relative; background: var(--panel); border-radius: 14px; max-width: 720px; width: 100%; max-height: 88vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-close { position: absolute; top: 10px; right: 10px; background: rgba(255, 255, 255, .9); border-radius: 50%; width: 32px; height: 32px; padding: 0; line-height: 1; }
.modal-poster { width: 100%; max-height: 42vh; object-fit: cover; display: block; background: #eee; }
.modal-body { padding: 20px 24px 24px; }
.modal-body h2 { margin: 0; font-size: 20px; }
.modal-note { white-space: pre-wrap; line-height: 1.7; margin: 0; }
.modal-info { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 12px 0; margin: 0 0 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 13px; }
.modal-info li { display: flex; gap: 6px; }
.modal-footer {
  position: sticky; bottom: 0; margin-top: 18px; padding: 14px 24px;
  margin-left: -24px; margin-right: -24px; margin-bottom: -24px;
  /* 평가 영역은 본문과 구분되도록 연한 배경을 깐다(흰 버튼이 도드라지게) */
  background: var(--bg); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 12px rgba(0, 0, 0, .04);
  max-height: 46vh; overflow: auto;
}
.modal-grades { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.modal-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.modal-nav .spacer { flex: 1 1 auto; }
.auto-next { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.auto-next input { width: 16px; height: 16px; }
.modal-grade-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grade-person { min-width: 64px; font-weight: 700; font-size: 13px; }
.grade-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.grade-btn { padding: 7px 12px; border-radius: 999px; font-size: 13px; background: var(--panel); color: var(--muted); }
.grade-btn:hover { border-color: var(--ink); }
.grade-btn.active { font-weight: 700; }
.grade-btn.active.g-must { background: var(--ink); color: #fff; border-color: var(--ink); }
.grade-btn.active.g-want { background: #e4eafa; color: #23407f; border-color: #c2d0ef; }
.grade-btn.active.g-maybe { background: #f2f0ea; color: #5f5c55; border-color: #ddd8cd; }
.grade-btn.active.g-none { background: #f1f1f2; color: #85858b; border-color: #e2e2e4; }
.grade-btn.active.g-unset { background: #fff; color: var(--ink); border-color: var(--ink); }
.grade-btn.g-unavailable { border-style: dashed; color: #a09a94; cursor: default; }

.modal-films { list-style: none; padding: 0; margin: 0 0 16px; }
.modal-films li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.btn-link { display: inline-block; padding: 6px 12px; border: 1px solid var(--ink); border-radius: 6px; background: var(--ink); color: #fff; text-decoration: none; }

/* 태블릿 */
@media (max-width: 900px) {
  .live-grid { grid-template-columns: 1fr; }
  .plan-list li { grid-template-columns: 28px 70px 60px 1fr; }
  .plan-list li > :last-child { grid-column: 2 / -1; }
  .grid2 { grid-template-columns: 1fr; }
}

/* 휴대폰 */
@media (max-width: 760px) {
  /* 타이포 스케일: 본문 15 / 보조 13 / 라벨 12 */
  body { font-size: 15px; }
  .small, .muted.small { font-size: 13px; }
  input, select, textarea, button { font-size: 16px; }
  .panel h2 { font-size: 15px; }
  .panel h3 { font-size: 14px; }

  main { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .panel { padding: 14px; border-radius: 10px; margin-bottom: 12px; }
  .row { gap: 10px; margin-bottom: 10px; }

  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar h1 { font-size: 15px; }
  .whoami { gap: 8px; font-size: 13px; }
  .conn { font-size: 11px; }
  #tabs { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  #tabs button { white-space: nowrap; padding: 8px 12px; font-size: 15px; }

  /* 작품 표 → 카드 목록 */
  table, tbody, td { display: block; width: 100%; }
  thead { display: none; }
  tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px 0; border-bottom: 1px solid var(--line); }
  td { border: none; padding: 0; }
  td[data-label=""], td[data-label="회차"] { grid-column: 1 / -1; }
  tbody td[data-label="회차"]:not([data-label=""])::before { display: none; } /* 라벨 표시 규칙보다 한 단계 구체적으로 */
  tbody td { padding: 0; }
  td[data-label]:not([data-label=""])::before {
    content: attr(data-label); display: block; margin-bottom: 4px;
    font-size: 12px; color: var(--muted);
  }
  td[data-label=""] a, td[data-label=""] b { font-size: 16px; }
  .chips { gap: 6px; }
  .chip { padding: 7px 12px; font-size: 13px; }
  .grade-select { width: 100%; padding: 9px 8px; }

  /* 입력 요소 */
  .row > input[type="datetime-local"], .row > input[type="text"], .row > input:not([type]), .row > select { flex: 1 1 100%; }
  input:not([type="checkbox"]):not([type="radio"]), select { max-width: 100%; min-width: 0; }
  label { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
  label > input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 auto; width: auto; }
  label > input[type="checkbox"] { width: 18px; height: 18px; flex: none; }

  /* 계획표 */
  .plan-list li { grid-template-columns: 22px auto 1fr; gap: 4px 8px; padding: 10px 0; }
  .plan-list li > :nth-child(1) { grid-column: 2; }
  .plan-list li > :nth-child(2) { grid-column: 3; justify-self: end; }
  .plan-list li > :nth-child(3) { grid-column: 2 / -1; }
  .plan-list li > :nth-child(4) { grid-column: 2 / -1; }

  /* 라이브 */
  .big-card { padding: 18px; }
  .big-card .big-code { font-size: 64px; }
  .big-card .title { font-size: 19px; }
  .big-card .meta { font-size: 15px; }
  .big-card .actions { gap: 8px; }
  .big-card .actions button { flex: 1 1 calc(50% - 4px); font-size: 17px; padding: 14px 8px; }
  .kbd { display: none; }
  .log { max-height: 240px; }
  .log li { flex-wrap: wrap; gap: 6px; }

  /* 모달 */
  /* 휴대폰에서도 화면 가운데에 뜨는 카드 */
  .modal-overlay {
    align-items: center;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  }
  .modal { max-height: 90vh; max-height: 90dvh; border-radius: 14px; }
  .modal-poster { max-height: 30vh; }
  .modal-body { padding: 16px; }
  .modal-body h2 { font-size: 19px; }
  .modal-info { gap: 6px 14px; font-size: 13px; }
  /* 이름과 평가 버튼 다섯 개를 한 줄에: 버튼은 같은 너비로 남은 폭을 나눠 쓴다 */
  .modal-grade-row { gap: 6px; flex-wrap: nowrap; }
  .grade-person { flex: 0 0 2.8em; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .grade-buttons { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 3px; }
  .grade-btn { flex: 1 1 0; min-width: 0; padding: 8px 2px; font-size: 12px; white-space: nowrap; text-align: center; }
  .grade-btn.g-unavailable { flex: 0 0 auto; padding: 8px 14px; }
  .modal-footer { padding: 12px 16px; margin: 14px -16px -16px; }
  .modal-grades { gap: 8px; margin-bottom: 10px; }
  .modal-nav { gap: 16px 6px; } /* 이전/다음 줄과 더 보기/닫기 줄 사이를 띄운다 */
  .modal-nav button { flex: 1 1 auto; }
  .modal-note { font-size: 15px; }
}

/* AI 한 줄 요약 */
.ai-summary { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-top: 14px; padding: 12px 14px; background: #f4f6fb; border-radius: 10px; font-size: 14px; }
.ai-badge { flex: none; font-size: 11px; font-weight: 700; letter-spacing: .3px; color: #4a5a86; background: #e2e8f6; border-radius: 4px; padding: 2px 7px; }
.ai-difficulty { margin-top: 8px; }
.difficulty-level { flex: none; font-weight: 800; font-size: 13px; padding: 1px 9px; border-radius: 999px; }
.difficulty-level.d-high { background: #fde7ea; color: #a4152c; }
.difficulty-level.d-mid { background: #fff1d6; color: #8a5a00; }
.difficulty-level.d-low { background: #e3f2e7; color: #1a6b31; }
