:root {
  color-scheme: light dark;
  --fg: #1c1c1c;
  --bg: #fdfcfa;
  --muted: #767676;
  --accent: #2f6fed;
  --border: #e4e0d8;
  --callout-bg: #e8f0ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #eee;
    --bg: #17181a;
    --muted: #9a9a9a;
    --accent: #6ea0ff;
    --border: #33353a;
    --callout-bg: #1e2a42;
  }
}

/* data-theme이 있으면 시스템 설정과 무관하게 강제 적용 (수동 토글) */
:root[data-theme="light"] {
  --fg: #1c1c1c;
  --bg: #fdfcfa;
  --muted: #767676;
  --accent: #2f6fed;
  --border: #e4e0d8;
  --callout-bg: #e8f0ff;
}
:root[data-theme="dark"] {
  --fg: #eee;
  --bg: #17181a;
  --muted: #9a9a9a;
  --accent: #6ea0ff;
  --border: #33353a;
  --callout-bg: #1e2a42;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

#root {
  max-width: 42rem;
  margin: 0 auto;
  padding: 3.25rem 1.25rem 6rem;
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}

#theme-toggle {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
}

h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }

.meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.callout {
  background: var(--callout-bg);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  padding: 0.7rem 0.9rem;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.work-list, .episode-list, .version-list {
  list-style: none;
  padding: 0;
}

.work-list > li { margin-bottom: 1.5rem; }
.episode-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.version-list {
  display: inline-flex;
  gap: 0.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.2rem 0.7rem;
  font-size: 0.9rem;
  touch-action: manipulation;
}

#content {
  font-size: 1.08rem;
  line-height: 1.9;
  user-select: text;
}

#content p { margin: 0 0 1.1em; }
#content p.scene-break {
  text-align: center;
  color: var(--muted);
  letter-spacing: 0.3em;
  margin: 1.6em 0;
}

.hint {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.comment-fab {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  min-height: 2.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 20;
  white-space: nowrap;
  touch-action: manipulation;
}

.comment-popover {
  position: absolute;
  z-index: 21;
  width: min(22rem, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.9rem;
  box-shadow: 0 4px 18px rgba(0,0,0,0.3);
}

.comment-popover blockquote {
  margin: 0 0 0.6rem;
  padding: 0.4rem 0.7rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 0.85rem;
  max-height: 5rem;
  overflow-y: auto;
}

.comment-popover textarea {
  width: 100%;
  min-height: 4.5rem;
  font-size: 1rem; /* 16px 미만이면 iOS Safari가 포커스 시 자동 확대함 */
  font-family: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}

.comment-popover input[type="text"] {
  width: 100%;
  font-size: 1rem;
  padding: 0.5rem;
  min-height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg);
  color: var(--fg);
  margin-top: 0.5rem;
}

.comment-popover .row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  gap: 0.5rem;
}

.comment-popover .warn {
  color: #d24;
  font-size: 0.8rem;
}

.comment-popover button.submit,
.comment-popover button.cancel {
  min-height: 2.5rem;
  font-size: 0.95rem;
  touch-action: manipulation;
}

.comment-popover button.submit {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0.4rem;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}
.comment-popover button.submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.comment-popover button.cancel {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.45rem 0.6rem;
}
