:root {
  --ground: #f5f1e8;  --card: #fffdf8;  --line: #e3ddcd;  --line-strong: #cfc8b4;
  --ink: #1f2721;     --muted: #62675d; --faint: #8a8d83;
  --green: #235343;   --green-dark: #1a4033; --green-soft: #e6eee6;
  --red: #b63d2b;     --red-soft: #f8e0da;   /* 빨강은 녹음 중·끝내기·오류에만 */
  --amber-soft: #fbedc8; --amber-ink: #765200;
  --r-card: 16px; --r-ctl: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --dock-h: 96px;
  --shadow: 0 1px 2px rgb(45 38 20 / .05), 0 12px 32px -18px rgb(45 38 20 / .22);
  background: var(--ground); color: var(--ink);
  font: 16px/1.6 -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  word-break: keep-all; -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p, ol, ul, figure, blockquote { margin: 0; padding: 0; }
h2 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
main { width: min(100% - 2rem, 68rem); margin-inline: auto; padding-block: 1.5rem 4rem; }
.muted { color: var(--muted); font-size: 13px; }
.muted:empty { display: none; }

/* 상단 */
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .9rem; min-height: 44px; margin-bottom: 1.75rem; }
.brand { display: flex; align-items: center; gap: .65rem; }
.brand h1 { font-size: 1.3rem; letter-spacing: -.02em; }
.mark { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: .7rem; background: var(--green); }
.mark i { width: .7rem; height: .7rem; border-radius: 50%; background: #ff7a62; box-shadow: 0 0 0 .25rem rgb(255 255 255 / .18); }
.team-bar { display: flex; align-items: center; gap: .6rem; }
.team-bar label { color: var(--muted); font-size: .9rem; font-weight: 600; white-space: nowrap; }
.team-bar select {
  min-width: 10rem; min-height: 44px; padding: 0 .75rem; font: inherit; font-weight: 600; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: .65rem; cursor: pointer;
}

/* 버튼 */
button {
  min-height: 48px; padding: .6em 1.1em; font: inherit; font-weight: 650; cursor: pointer;
  color: #fff; background: var(--green); border: 1px solid transparent; border-radius: .7rem;
  transition: background-color .15s, transform .1s;
}
button:hover:enabled { background: var(--green-dark); }
button:active:enabled { transform: translateY(1px); }
button:disabled { background: #ece8dd; color: #737067; border-color: transparent; cursor: default; }
button.secondary, button.ghost { background: var(--card); color: var(--green); border-color: #cfd6c9; }
button.secondary:hover:enabled, button.ghost:hover:enabled { background: var(--green-soft); }
button.secondary:disabled { background: #ece8dd; color: #737067; border-color: transparent; }
button.ghost { min-height: 44px; color: var(--muted); border-color: var(--line); white-space: nowrap; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }

/* 로그인 전 */
.note { color: var(--muted); }
main > #status { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 12px 16px; }
.landing { display: grid; grid-template-columns: minmax(0, 560fr) minmax(0, 464fr); gap: 40px 64px; align-items: center; align-content: center; min-height: calc(100dvh - 140px); padding-top: 0; }
.eyebrow { color: var(--green); font-weight: 700; font-size: 13px; margin-bottom: var(--s3); }
.hero h2 { font-size: clamp(2rem, 4.6vw, 52px); font-weight: 700; line-height: 1.2; letter-spacing: -.035em; }
.hero h2 span { display: block; }
.lead { text-wrap: pretty; margin-block: 20px var(--s6); max-width: 31rem; color: var(--muted); font-size: 17px; }
.google { display: inline-flex; align-items: center; justify-content: center; gap: .75rem; min-height: 54px; padding-inline: 1.5rem; font-size: 17px; }
.google svg { width: 1.9rem; height: 1.9rem; padding: .35rem; margin-left: -.55rem; border-radius: .45rem; background: #fff; }
.note-slot .note { margin-top: var(--s3); font-size: 13px; }
.steps-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); }
.steps { display: grid; grid-template-columns: minmax(0, 1fr); list-style: none; counter-reset: step; }
.steps li { position: relative; counter-increment: step; display: grid; grid-template-columns: auto 1fr; column-gap: var(--s3); align-content: start; padding: var(--s5); }
.steps li + li { border-top: 1px solid var(--line); }
.steps li::before { content: counter(step); grid-row: span 2; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: #fff; font-weight: 700; font-size: 13px; }
.steps h3 { font-size: 18px; font-weight: 700; line-height: 32px; }
.steps p { color: var(--muted); font-size: 15px; }
.steps-foot { padding: 14px var(--s5); border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* 로그인 후 */
.workspace { display: grid; grid-template-columns: 22.5rem minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "recorder reader" "library reader"; gap: 24px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 1.4rem; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .35rem 1rem; }
.recorder { grid-area: recorder; text-align: center; transition: border-color .2s; }
.recorder .card-head { text-align: left; min-height: 1.8rem; }
.live { display: none; align-items: center; gap: .4rem; color: var(--red); font-size: .85rem; font-weight: 700; }
.live::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
.recorder:has(#stop:enabled) { border-color: var(--red); }
.recorder:has(#stop:enabled) .live { display: inline-flex; }
.recorder:has(#stop:enabled) :is(#timer, #limit) { color: var(--red); }
.recorder:has(#stop:enabled) #stop { background: var(--red); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live::before { animation: none; } button { transition: none; } }
.clock { display: flex; justify-content: center; align-items: baseline; gap: .5rem; margin-block: .6rem 1rem; font-variant-numeric: tabular-nums; }
#timer { font-size: 3rem; font-weight: 700; line-height: 1.15; letter-spacing: -.03em; }
#limit { color: var(--muted); font-size: 1.1rem; }
.recorder .controls { display: grid; grid-template-columns: 1fr; gap: .6rem; }
.recorder:has(#stop:enabled) #start, .recorder:not(:has(#stop:enabled)) #stop { display: none; }
#start, #stop { min-height: 56px; font-size: 1.05rem; }
.recorder:has(#stop:enabled) #limit-hint { display: none; }
.recorder:has(#stop:enabled) #recorder-note .note { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.recorder-foot { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line); font-size: 13px; text-align: left; }
.recorder:has(#stop:enabled) .recorder-foot { display: contents; }
#limit-hint { color: var(--muted); }
#recorder-note .note { margin-top: .2rem; color: var(--green); font-weight: 650; }

.library { grid-area: library; padding-inline: .75rem; }
.library h2, #list-empty { padding-inline: .65rem; }
#list-empty { margin-top: .75rem; }
#recordings { list-style: none; margin-top: .65rem; max-height: none; }
.workspace:has(#stop:enabled) .library { opacity: .55; pointer-events: none; }
#recordings li + li { border-top: 1px solid var(--line); }
#recordings a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem; align-items: center;
  min-height: 64px; align-content: center; margin-block: .2rem; padding: .6rem .65rem; border-radius: .7rem; color: inherit; text-decoration: none; outline-offset: -3px;
}
#recordings a:hover { background: #f4f1e7; }
#recordings a[aria-current] { background: var(--green-soft); box-shadow: inset 3px 0 0 var(--green); }
.when { font-weight: 650; font-size: 15px; }
.snippet { grid-column: 1 / -1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 14px; }
.badge { padding: .1rem .55rem; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #ece8dd; color: var(--muted); }
.badge.ready { background: #dcebdd; color: #1d5236; }
.badge.pending { background: #fbedc8; color: #765200; }
.badge.failed { background: #f8e0da; color: #97301f; }

.reader { grid-area: reader; position: sticky; top: 1rem; min-width: 0; scroll-margin-block: 1rem; }
.reader > .card { min-height: calc(100dvh - 8rem); }
.empty { display: grid; justify-items: center; align-content: center; gap: .6rem; text-align: center; border-style: dashed; box-shadow: none; }
.empty p { max-width: 22rem; color: var(--muted); }
.empty-icon { display: flex; align-items: center; gap: 5px; height: 3rem; }
.empty-icon i { width: 6px; height: 35%; border-radius: 6px; background: #a9bbae; }
.empty-icon i:nth-child(2n) { height: 70%; }
.empty-icon i:nth-child(3) { height: 100%; }
.result { display: flex; flex-direction: column; padding: 1.75rem; }
.result .card-head { flex-direction: column; align-items: flex-start; gap: 2px; }
.result .controls { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: var(--s4); padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.result .controls button { min-height: 44px; }
#transcript { flex: 1; max-width: 38em; padding-block: var(--s2) var(--s5); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 20px; line-height: 1.75; }
#result-note { margin-top: .75rem; }
.summary { margin-top: var(--s4); padding: var(--s4); border-radius: var(--r-ctl); background: var(--green-soft); }
.summary h3, .transcript-title { font-size: 14px; font-weight: 700; color: var(--green); }
#summary { margin-top: var(--s2); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 18px; line-height: 1.7; }
#summary:empty { display: none; }
#summary-note { margin-top: var(--s2); font-size: 13px; }
.transcript-title { margin-top: var(--s5); }
#audio { display: block; width: 100%; margin-top: 1rem; }

/* 실시간 받아쓰기 */
.live-card { display: flex; flex-direction: column; border-color: var(--red); }
.workspace:not(:has(#stop:enabled)) .live-card { border-color: var(--line); }
.live-state { display: inline-flex; align-items: center; gap: 6px; color: var(--red); font-size: 13px; font-weight: 700; }
.live-state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
.workspace:not(:has(#stop:enabled)) .live-state { display: none; }
#live-title { font-size: 17px; font-weight: 600; }
#live-text { flex: 1; max-height: none; overflow-y: auto; overflow-wrap: anywhere; margin-top: 16px; font-size: 20px; line-height: 1.75; }
#live-text span { display: block; padding: 2px 0; }
#live-text span:empty:not(:last-child) { display: none; } /* 아직 안 온 앞 조각은 자리만 */
#live-text span:last-child:empty { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--green-soft); color: var(--green); font-size: 15px; font-weight: 650; }
#live-text span:last-child:empty::before { content: "받아 적는 중"; }
#live-text span:last-child:empty::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 6px; vertical-align: -2px; background: currentColor; animation: pulse 1s steps(2) infinite; }
.workspace:not(:has(#stop:enabled)) #live-text span:last-child:empty::before { content: "전체 녹음을 다시 받아쓰는 중"; }
#live-note { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
/* 녹음 중에는 빈 안내 카드를 숨기고, 끝낸 뒤 받아쓰는 동안에는 얇은 상태 줄로 */
.workspace:has(#stop:enabled) #result-empty { display: none; }
.reader:has(#live:not([hidden])) #result-empty { min-height: 0; margin-top: 12px; padding: 12px 16px; border-style: solid; justify-items: start; text-align: left; }
.reader:has(#live:not([hidden])) #result-empty :is(.empty-icon, h2) { display: none; }
.reader:has(#live:not([hidden])) .live-card { min-height: calc(100dvh - 12rem); }
@media (prefers-reduced-motion: reduce) { .live-state::before, #live-text span:last-child:empty::after { animation: none; } }

@media (max-width: 54rem) {
  main { width: min(100% - 32px, 34rem); padding-block: 1rem 2.5rem; }
  main:has(#workspace:not([hidden])) { padding-bottom: calc(var(--dock-h) + 32px + env(safe-area-inset-bottom)); }
  main:has(#workspace:not([hidden]) #status[data-tone="error"]) { padding-bottom: calc(var(--dock-h) + 112px + env(safe-area-inset-bottom)); } /* 오류 문구로 커진 도크 */
  .topbar { margin-bottom: 1.1rem; }
  .team-bar { width: 100%; }
  .team-bar select { flex: 1; min-width: 0; }
  .landing { grid-template-columns: minmax(0, 1fr); gap: var(--s5); min-height: 0; }
  .hero { padding-top: 12px; }
  .hero h2 { font-size: 34px; line-height: 1.22; }
  .lead { margin-block: var(--s4) var(--s5); font-size: 16px; }
  .google { width: 100%; }
  .steps li { padding: var(--s4); }
  .steps-foot { padding-inline: var(--s4); }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "reader" "library"; gap: 1rem; }
  .card { padding: 1.15rem; }
  .library { padding-inline: .5rem; }
  .reader { position: static; }
  .reader > .card { min-height: 9rem; }
  .reader:has(#live:not([hidden])) .live-card { min-height: calc(100dvh - var(--dock-h) - 11rem); }
  .workspace:not(:has(#stop:enabled)) .reader:has(#live:not([hidden])) .live-card { min-height: calc(100dvh - var(--dock-h) - 14rem); } /* 종료 직후 상태 줄이 도크에 가리지 않게 */
  #transcript, #live-text { font-size: 18px; }
  #summary { font-size: 17px; }
  #transcript { padding-block: var(--s2) var(--s5); }
  .result .controls { display: grid; grid-template-columns: 1fr 1fr; }
  /* 녹음 조작은 하단 도크 */
  .recorder { grid-area: auto; position: fixed; inset: auto 0 0 0; z-index: 10; border-radius: 16px 16px 0 0; border-width: 1px 0 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px -16px rgb(45 38 20 / .35);
    display: grid; grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "clock btn" "foot foot"; align-items: center; gap: 4px 12px; text-align: left; }
  .recorder .card-head { position: absolute; top: 10px; left: 16px; min-height: 0; }
  .recorder .card-head h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .recorder .clock { grid-area: clock; justify-content: flex-start; margin: 14px 0 0; }
  #timer { font-size: 1.75rem; }
  #limit { font-size: .95rem; }
  .recorder .controls { grid-area: btn; }
  #start, #stop { min-width: 136px; min-height: 52px; }
  .recorder-foot { grid-area: foot; margin: 0; padding: 0; border: 0; font-size: 13px; }
  #limit-hint { display: none; }
}

/* 오류 표시 */
#status[data-tone="error"], #result-message[data-tone="error"] { max-width: none; color: #97301f; background: var(--red-soft); border-radius: 10px; padding: 10px 12px; text-align: left; font-weight: 600; font-size: 16px; }
