:root {
  --bg: #f3f7f6;
  --surface: #ffffff;
  --sunken: #e8efed;
  --fg: #13201d;
  --muted: #55655f;
  --line: #d2ddd9;
  --accent: #0c6a63;
  --accent-soft: #d8ede9;
  --ink: #1b2f8f;
  --rec: #c2352b;
  --warn: #a4500a;
  --warn-soft: #fbead2;
  --paper-line: #e3ebe8;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* display를 지정한 요소(.busy, #res-body 등)도 hidden 속성이면 숨긴다 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }

/* 상단 막대 */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: calc(.5rem + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) .5rem max(12px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.group { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.group.end { margin-left: auto; }
.status { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.status i { width: .6rem; height: .6rem; border-radius: 50%; background: var(--line); }
.status.on { color: var(--rec); font-weight: 600; }
.status.on i { background: var(--rec); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.meter { width: 70px; height: 8px; border-radius: 4px; background: var(--sunken); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .08s linear; }

.btn {
  min-height: 44px; padding: 0 .9rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font: 600 .95rem/1 inherit; font-family: inherit; cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn.small { min-height: 34px; padding: 0 .7rem; font-size: .85rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.rec { color: var(--rec); border-color: var(--rec); display: inline-flex; align-items: center; gap: .45rem; }
.btn.rec .dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--rec); }
.btn.tool.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, .tab:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.toggle { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; color: var(--muted); padding: 0 .3rem; }
.toggle input { width: 1.2rem; height: 1.2rem; }

.notice {
  margin: 0; padding: .6rem max(12px, env(safe-area-inset-left, 0px));
  background: var(--warn-soft); color: var(--warn); font-size: .92rem; border-bottom: 1px solid var(--line);
}

/* 필기 + 결과 */
.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr; }
.stage.with-results { grid-template-columns: 1fr minmax(320px, 38%); }
@media (orientation: portrait) {
  .stage.with-results { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
}
.paper-wrap { position: relative; min-height: 0; min-width: 0; padding: 12px max(12px, env(safe-area-inset-left, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)); }
#pad {
  display: block; width: 100%; height: 100%;
  background-color: #fff;
  background-image: repeating-linear-gradient(to bottom, transparent 0 39px, var(--paper-line) 39px 40px);
  border: 1px solid var(--line); border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
}
.hint { position: absolute; left: 28px; right: 28px; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); margin: 0; font-size: .85rem; color: var(--muted); pointer-events: none; }

.results {
  min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 12px max(14px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) 14px;
  -webkit-user-select: text; user-select: text;
  display: flex; flex-direction: column; gap: .75rem;
}
@media (orientation: portrait) { .results { border-left: 0; border-top: 1px solid var(--line); } }
.res-head { display: flex; justify-content: space-between; align-items: center; }
.share-menu {
  position: fixed; z-index: 30; width: min(19rem, calc(100vw - 24px));
  display: grid; gap: .4rem; padding: .7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(19, 32, 29, .18);
}
.share-menu .btn { justify-content: flex-start; text-align: left; }
.share-note { margin: .2rem 0 0; font-size: .78rem; color: var(--muted); line-height: 1.5; }
.busy { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .95rem; }
.spinner { width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 3px solid var(--sunken); border-top-color: var(--accent); animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
#res-body { display: flex; flex-direction: column; gap: .7rem; }
.meta { margin: 0; font-size: .82rem; color: var(--muted); }
.warnings { margin: 0; padding: 0; list-style: none; display: grid; gap: .3rem; }
.warnings li { font-size: .85rem; color: var(--warn); background: var(--warn-soft); border-radius: 8px; padding: .35rem .6rem; }
#playback { width: 100%; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: .5rem .75rem; font: 600 .92rem inherit; font-family: inherit; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; min-height: 40px; }
.tab.is-on { color: var(--accent); border-bottom-color: var(--accent); }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.item { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: .55rem .6rem; border-radius: 10px; border: 1px solid var(--line); }
.item .when { grid-row: span 2; display: grid; gap: .2rem; align-content: start; justify-items: start; }
.item .t { font-size: .8rem; color: var(--muted); background: none; border: 1px solid var(--line); border-radius: 6px; padding: .1rem .4rem; cursor: pointer; font-family: ui-monospace, Menlo, monospace; min-height: 30px; }
.badge { font-size: .72rem; font-weight: 700; padding: .05rem .4rem; border-radius: 5px; }
.badge.audio { background: var(--sunken); color: var(--fg); }
.badge.ink { background: #e4e9fb; color: var(--ink); }
.item .text { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item.ink .text { color: var(--ink); }
.item .text.unread { color: var(--warn); font-style: italic; }
.item > img, .item > .note { grid-column: 2; }
.item img { max-width: 100%; max-height: 120px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.item .note { font-size: .8rem; color: var(--muted); }
.empty { color: var(--muted); font-size: .9rem; }
.sec { font-size: .78rem; font-weight: 700; color: var(--muted); margin-top: .3rem; letter-spacing: .02em; }
.badge.both { background: var(--accent-soft); color: var(--accent); }
.item.final .text { font-weight: 600; }
.item.final.check { border-color: var(--warn); background: var(--warn-soft); }
.item .note.warn { color: var(--warn); font-weight: 600; }

@media (max-width: 700px) {
  .group.end { margin-left: 0; }
  .meter { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .status.on i, .spinner { animation: none; }
}
