/* 한국사 연표 퍼즐 — 글자와 도형만. 흑백에 강조색 하나(쪽빛). 폰 세로 화면(폭 360~430) 기준. */
:root {
  --paper: #ffffff;
  --ink: #16202e;
  --muted: #566274;
  --rule: #c6ced9;
  --wash: #e8eef6;
  --accent: #24508f;
  --tap: 44px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 100%;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; color: var(--ink); background: var(--paper); }
/* 넘김 막대의 자리를 늘 남겨 둔다: 더 알아보기 창이 열려 막대가 사라져도 화면이 옆으로 밀리지 않는다(막대가 겹쳐 뜨는 폰에서는 달라지는 것 없음) */
html { scrollbar-gutter: stable; }
body { word-break: keep-all; overflow-wrap: anywhere; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app { max-width: 480px; margin: 0 auto; }
.boot { padding: 48px 16px; text-align: center; }

/* 화면 틀 */
.screen { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  min-height: var(--tap);
  padding: env(safe-area-inset-top, 0px) 4px 0 16px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.top-title {
  flex: 0 1 auto; display: flex; align-items: center;
  min-width: 0; min-height: var(--tap); margin: 0; padding: 0;
  font-size: 1rem; font-weight: 700; text-align: left;
  background: none; border: 0;
}
button.top-title { cursor: pointer; }
/* 누르는 제목 = 시대를 고르는 단추. 테두리와 세모로 눌리는 곳임을 보인다(누르는 높이는 단추 전체 44px, 테두리는 그 안의 32px) */
.top-title .pick { display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; background: var(--paper); border: 1.5px solid var(--ink); border-radius: 6px; }
.top-title .pick::after { content: "▾"; margin-left: 6px; font-size: 0.875rem; }
button.top-title:hover .pick, button.top-title:active .pick { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.top-status { flex: 1 1 auto; font-size: 0.875rem; text-align: right; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.top-about {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap); padding: 0 8px;
  font-size: 0.875rem; text-decoration: none;
}
.body { flex: 1 1 auto; padding: 8px 16px 16px; }
.bottom {
  position: sticky; bottom: 0; z-index: 2;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--paper); border-top: 1px solid var(--rule);
}

/* 단추 */
.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: var(--tap); margin: 8px 0 0; padding: 10px 16px;
  font-weight: 600; text-align: center; text-decoration: none;
  color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 6px; cursor: pointer;
}
.btn.primary { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.bottom > .btn:first-child { margin-top: 0; }

/* 연표 */
.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline::before { content: ""; position: absolute; top: 0; bottom: 0; left: 21px; width: 2px; background: var(--ink); }
.slot { position: relative; }
.slot-btn { display: flex; align-items: center; width: 100%; height: var(--tap); padding: 0; background: none; border: 0; cursor: pointer; }
.slot-btn .plus {
  flex: 0 0 28px; display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; margin-left: 8px;
  font-size: 1.125rem; line-height: 1;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 50%;
}
.slot-btn::after { content: ""; flex: 1 1 auto; margin-left: 10px; border-top: 1.5px dashed var(--rule); }
.slot-btn:hover .plus, .slot-btn:active .plus { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.era-mark { position: relative; padding: 6px 0 2px 44px; font-size: 0.75rem; color: var(--muted); }
.card { position: relative; padding: 2px 0 2px 44px; }
.card::before { content: ""; position: absolute; top: 19px; left: 17px; width: 10px; height: 10px; background: var(--ink); border-radius: 50%; }
.card-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: var(--tap); padding: 8px 12px; text-align: left;
  background: var(--paper); border: 1px solid var(--ink); border-radius: 6px; cursor: pointer;
}
.card-btn .name { flex: 1 1 auto; min-width: 0; }
.card-btn .year { flex: 0 0 auto; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.card-btn .kind { display: block; font-size: 0.6875rem; color: var(--muted); }
.card.open::before { background: var(--accent); }
.card.open .card-btn { font-weight: 700; background: var(--wash); border: 2px solid var(--accent); border-bottom: 0; border-radius: 6px 6px 0 0; }
.card .line { margin: 0; padding: 4px 12px 10px; font-size: 0.875rem; background: var(--wash); border: 2px solid var(--accent); border-top: 0; border-radius: 0 0 6px 6px; }

/* 움직임은 이것 하나: 놓은 카드가 자리로 옮겨 온다(0.3초) */
@keyframes from-below { from { transform: translateY(24px); opacity: 0.2; } to { transform: none; opacity: 1; } }
@keyframes from-above { from { transform: translateY(-24px); opacity: 0.2; } to { transform: none; opacity: 1; } }
.card.from-below { animation: from-below 0.3s ease-out; }
.card.from-above { animation: from-above 0.3s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .card.from-below, .card.from-above { animation: none; }
}

/* 아래 고정: 새 카드 */
.hint { margin: 0 0 8px; font-size: 0.875rem; font-weight: 600; color: var(--accent); }
.newcard {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding: 8px 12px;
  background: var(--wash); border: 2px dashed var(--accent); border-radius: 6px;
}
.newcard .label { flex: 0 0 100%; font-size: 0.75rem; color: var(--muted); }
.newcard .name { flex: 1 1 auto; min-width: 0; font-size: 1.25rem; }
.newcard .ask { flex: 0 0 auto; font-size: 0.8125rem; color: var(--muted); }
.round-end { margin: 0; font-weight: 600; text-align: center; }
/* PC(마우스): 새 카드를 끌어 연표에 놓을 수 있다. 끄는 동안 가장 가까운 틈이 진해진다(마우스를 올린 틈과 같은 모양). */
.newcard.draggable { cursor: grab; -webkit-user-select: none; user-select: none; }
.newcard.draggable:active { cursor: grabbing; }
.newcard.dragging { opacity: 0.5; }
.timeline.dropping .slot.near .plus { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.timeline.dropping .slot.near .slot-btn::after { border-top: 2px solid var(--accent); }

/* 더 알아보기 창 */
.sheet-wrap { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: rgba(22, 32, 46, 0.45); }
.sheet {
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--paper); border-radius: 12px 12px 0 0;
}
.sheet-name { margin: 0; font-size: 1.25rem; }
.sheet-year { margin: 2px 0 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet-line { margin: 0 0 8px; font-weight: 600; }
.sheet-more { margin: 0 0 12px; }
.sheet-src-h { margin: 0 0 4px; font-size: 0.8125rem; color: var(--muted); }
.sheet-src { margin: 0 0 8px; padding-left: 18px; font-size: 0.875rem; }
.sheet-src a { display: inline-flex; align-items: center; min-height: var(--tap); }
/* 창이 열려 있는 동안에는 뒤의 연표를 넘기지 않는다 */
html:has(.sheet-wrap) { overflow: hidden; }

/* 판 끝 */
.result { padding-top: 24px; text-align: center; }
.result-title { margin: 0 0 8px; font-size: 1.5rem; }
.marks { margin: 0 0 16px; font-size: 1.375rem; letter-spacing: 2px; }
.copied, .copy-help { margin: 8px 0 0; font-size: 0.875rem; }
.copy-fallback { width: 100%; margin-top: 8px; padding: 8px; font: inherit; font-size: 0.875rem; border: 1.5px solid var(--ink); border-radius: 6px; resize: none; }
.finish { margin: 24px 0 0; padding-top: 16px; font-weight: 600; border-top: 1px solid var(--rule); }
.met { margin: 8px 0 0; font-size: 0.875rem; }
.bottom .round-end + .btn { margin-top: 8px; }

/* 시대 고르기 */
.map { padding-top: 8px; }
.line-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; margin: 0 0 8px; padding: 8px 12px;
  color: var(--ink); text-decoration: none;
  border: 1px solid var(--ink); border-radius: 6px;
}
.line-item.locked, .line-item.soon { color: var(--muted); border-style: dashed; border-color: var(--rule); }
.line-name { flex: 0 1 auto; min-width: 0; }
.line-state { flex: 0 1 auto; font-size: 0.8125rem; text-align: right; font-variant-numeric: tabular-nums; }
.line-run, .line-met { display: block; }
.line-met { font-size: 0.75rem; color: var(--muted); }
.map-h { margin: 20px 0 8px; font-size: 1rem; }
.eras { margin: 0 0 8px; padding: 0; list-style: none; }
.era-row { display: flex; gap: 8px; }
.era-no { flex: 0 0 20px; padding-top: 34px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.era-body { flex: 1 1 auto; min-width: 0; }
.era-sub { display: block; margin-bottom: 2px; font-size: 0.75rem; color: var(--muted); }

/* 안내 */
.about h2 { margin: 20px 0 6px; font-size: 1rem; }
.about p, .about ol { margin: 0 0 8px; }
.about ol { padding-left: 20px; }
.about .warn { padding: 8px 12px; font-weight: 600; border: 1.5px solid var(--ink); border-radius: 6px; }
.about-links { margin: 0 0 8px; padding-left: 20px; font-size: 0.875rem; }
.about-links a { display: inline-flex; align-items: center; min-height: var(--tap); }
