/* NOVA 웹 — 폰·폴드·태블릿용 덧칠. tv.css 위에 얹습니다 (슬레이트의 tv/ 는 그대로).
   화면 크기는 기기마다 다르므로 vw·vh 대신 "짧은 변(vmin)"과 실제 보이는 높이(dvh)를 기준으로 맞춥니다.
   배치는 세 가지: 세로 폰(폴드 접힘 포함) · 가로 폰 · 태블릿(아이패드·폴드 펼침). */
#touchbar { display: none; }

@media (max-width: 900px), (pointer: coarse) {
  :root {
    --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
    --gut: max(12px, 3.2vmin);                 /* 가장자리 여백 */
    --head: calc(var(--sat) + 52px);           /* 위쪽 상태 줄 높이 */
    --bar: calc(var(--sab) + 68px);            /* 아래 단추 줄 높이 */
    --big: clamp(17px, calc(1.5vmin + 11px), 30px);
    --hud: clamp(11px, calc(.6vmin + 9px), 15px);
    --vh: 1vh;
  }
  @supports (height: 1dvh) { :root { --vh: 1dvh; } }  /* 주소창이 나타났다 사라져도 실제 보이는 높이로 */
  html, body { cursor: default; height: calc(var(--vh) * 100); -webkit-tap-highlight-color: transparent; }
  body { overscroll-behavior: none; touch-action: manipulation; }  /* 두 번 눌러 확대·당겨서 새로 고침 막기 */

  .frame, #log, #keys, #scan, #date, .secbar, #home #hint .by-key, #mini, #view header .hint { display: none !important; }

  /* 위쪽: 상태(왼쪽) · 시계(오른쪽) 한 줄 */
  #sys { top: calc(var(--sat) + 10px); left: calc(var(--sal) + var(--gut)); }
  #sys .brand { margin-bottom: 4px; }
  #sys dl { display: none; }                                    /* 자세한 상태는 숨기고 */
  #sys .brand small { display: none; }
  #sys .brand::after { display: none; }
  #sys .brand b::after { content: ""; display: inline-block; vertical-align: middle; width: 8px; height: 8px; border-radius: 50%; background: rgba(150, 200, 240, .3); margin-left: 8px; }
  body.online #sys .brand b::after { background: #5cf2a0; box-shadow: 0 0 8px #5cf2a0; } /* 연결 표시 점 (phone.js 가 online 을 붙임) */
  #time { top: calc(var(--sat) + 8px); right: calc(var(--sar) + var(--gut)); }
  #clock { font-size: clamp(22px, calc(2.4vmin + 14px), 40px) !important; }
  #fresh { position: fixed; top: calc(var(--sat) + 12px); left: 50%; transform: translateX(-50%); margin: 0; }

  /* 가운데 코어: 위·아래 줄 사이의 빈 곳 한가운데 */
  #coreWrap { --cs: min(72vw, calc((var(--vh) * 100 - var(--head) - var(--bar)) * .62), 520px);
    width: var(--cs); height: var(--cs); top: calc(var(--head) + (var(--vh) * 100 - var(--head) - var(--bar)) * .44); }
  #home { bottom: calc(var(--bar) + 2.5 * var(--vh)); padding: 0 var(--gut); }
  #greet { font-size: clamp(20px, calc(2vmin + 14px), 34px); }
  #coreText { transform: translate(-50%, 0); }

  /* 답 패널: 위·아래 줄 사이를 채움. 답이 뜨면 코어는 왼쪽 위에 작게 */
  #panel { left: calc(var(--sal) + var(--gut)); right: calc(var(--sar) + var(--gut)); width: auto;
    top: calc(var(--head) + 6px); bottom: calc(var(--bar) + 6px); padding: 14px clamp(14px, 4vmin, 32px) 10px; gap: 10px; transform: translateY(3vh); }
  #panel header { gap: 10px; padding-bottom: 10px; }
  #heard { font-size: calc(var(--big) * .72); }
  body.has-answer:not(.listening) #coreWrap { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  body.viewing #coreWrap { display: none; }

  /* 띄운 화면(영상·목록·사진): 위·아래 줄 사이 전체. 답은 그 아래쪽에 자막처럼 */
  #view { left: calc(var(--sal) + var(--gut)) !important; right: calc(var(--sar) + var(--gut)) !important;
    top: calc(var(--head) + 6px) !important; bottom: calc(var(--bar) + 6px) !important; width: auto !important; height: auto !important; }
  body.cinema #view { left: var(--sal) !important; right: var(--sar) !important; top: var(--sat) !important; bottom: var(--bar) !important; }
  body.viewing.has-answer:not(.quiet):not(.nocap):not(.cinema) #view { bottom: calc(var(--bar) + 34%) !important; }
  body.viewing #panel { top: auto; left: calc(var(--sal) + var(--gut)); right: calc(var(--sar) + var(--gut)); bottom: calc(var(--bar) + 10px); max-height: 32%; }
  body.cinema #panel { left: calc(var(--sal) + var(--gut)); right: calc(var(--sar) + var(--gut)); bottom: calc(var(--bar) + 10px); max-height: 26%; }

  #typeForm { left: calc(var(--sal) + var(--gut)); right: calc(var(--sar) + var(--gut)); width: auto; transform: none; bottom: calc(var(--bar) + 8px); }
  #typeForm input { font-size: 16px; } /* 16px 아래면 아이폰이 화면을 확대함 */
  #setup .box { width: min(520px, calc(100vw - 2 * var(--gut))); padding: 32px clamp(18px, 6vmin, 36px) 24px; font-size: 16px; gap: 14px; max-height: calc(var(--vh) * 92); overflow-y: auto; }
  #setup .row { flex-wrap: wrap; gap: 10px; }
  #setup h1 { letter-spacing: .02em; font-size: 24px; }
  #setup button { letter-spacing: .05em; }
  #confirm .box { min-width: 0; width: min(560px, calc(100vw - 2 * var(--gut))); max-width: none; padding: 24px clamp(16px, 5vmin, 36px); font-size: 18px; }

  /* 아래 단추 줄 */
  #touchbar { display: flex; flex-wrap: nowrap; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: var(--bar);
    gap: clamp(4px, 1.6vmin, 14px); justify-content: center; align-items: center;
    padding: 0 calc(var(--sar) + 8px) var(--sab) calc(var(--sal) + 8px); background: linear-gradient(0deg, rgba(1, 2, 7, .96) 60%, rgba(1, 2, 7, 0)); }
  #touchbar button { font: inherit; font-size: clamp(12px, calc(.9vmin + 9px), 16px); color: var(--ink); background: rgba(var(--c), .08);
    border: 1px solid rgba(var(--c), .35); border-radius: 12px; height: 46px; padding: 0 clamp(8px, 2vmin, 18px); white-space: nowrap; flex: 0 1 auto; min-width: 0; }
  #touchbar button.talk { font-size: clamp(15px, calc(1vmin + 12px), 19px); height: 54px; padding: 0 clamp(16px, 4vmin, 36px); background: rgba(var(--c), .22); border-color: rgb(var(--c)); }
  body.listening #touchbar button.talk { background: rgba(var(--c), .5); }
  body.wake-on #touchbar .wakebtn { background: rgba(92, 242, 160, .25); border-color: #5cf2a0; }
}

/* 아주 좁은 폰(폴드 접힘·작은 아이폰): 단추 글자를 줄이고 "새 대화"는 아이콘처럼 짧게 */
@media (max-width: 380px) {
  #touchbar button { padding: 0 7px; font-size: 12px; }
  #touchbar button.talk { padding: 0 14px; }
}

/* 가로로 눕힌 폰 (높이가 낮음): 코어는 왼쪽, 답은 오른쪽, 단추는 오른쪽 세로 줄 */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --head: calc(var(--sat) + 44px); --bar: 0px; --side: calc(var(--sar) + 84px); --big: clamp(15px, calc(1.6vmin + 9px), 24px); }
  #touchbar { left: auto; top: 0; bottom: 0; right: 0; width: var(--side); height: auto; flex-direction: column; justify-content: center;
    gap: 6px; padding: calc(var(--sat) + 6px) calc(var(--sar) + 6px) calc(var(--sab) + 6px) 6px; background: linear-gradient(270deg, rgba(1, 2, 7, .96) 70%, rgba(1, 2, 7, 0)); }
  #touchbar button { height: 36px; width: 100%; padding: 0 4px; font-size: 12px; }
  #touchbar button.talk { height: 48px; font-size: 15px; padding: 0 4px; order: -1; }
  #time { right: calc(var(--side) + 8px); }
  #coreWrap { --cs: min(40vw, calc(var(--vh) * 100 - var(--head) - 20px)); left: calc(var(--sal) + 6px + 21vw); top: calc(var(--head) + (var(--vh) * 100 - var(--head)) * .48); }
  #home { left: auto; right: var(--side); width: 50vw; bottom: 40%; text-align: center; }
  #panel, body.viewing #panel, body.cinema #panel { left: calc(var(--sal) + var(--gut)); right: calc(var(--side) + 6px); top: calc(var(--head) + 4px); bottom: calc(var(--sab) + 8px); max-height: none; }
  body.viewing #panel, body.cinema #panel { top: auto; max-height: 38%; }
  #view { right: calc(var(--side) + 4px) !important; bottom: calc(var(--sab) + 6px) !important; }
  body.cinema #view { right: var(--side) !important; bottom: 0 !important; }
  body.viewing.has-answer:not(.quiet):not(.nocap):not(.cinema) #view { bottom: calc(38% + 12px) !important; }
  #typeForm { right: calc(var(--side) + 8px); bottom: calc(var(--sab) + 8px); }
}

/* 태블릿·폴드 펼침 (넓고 높음): 글자와 단추를 키우고, 답은 가운데 넓은 칸에 */
@media (pointer: coarse) and (min-width: 600px) and (min-height: 600px) {
  :root { --head: calc(var(--sat) + 64px); --bar: calc(var(--sab) + 84px); --big: clamp(20px, calc(1.4vmin + 12px), 34px); --hud: clamp(13px, calc(.5vmin + 10px), 17px); }
  #touchbar button { height: 54px; font-size: 16px; padding: 0 20px; }
  #touchbar button.talk { height: 64px; font-size: 20px; padding: 0 44px; }
  #panel { left: max(calc(var(--sal) + var(--gut)), calc(50vw - 460px)); right: max(calc(var(--sar) + var(--gut)), calc(50vw - 460px)); }
  body.viewing #panel, body.cinema #panel { left: max(var(--gut), calc(50vw - 420px)); right: max(var(--gut), calc(50vw - 420px)); }
  #sys dl { display: block; margin-top: 8px; }
  #sys dl > div:nth-child(n+3) { display: none; }  /* 링크·폴더만 */
  #sys .brand small { display: inline; }
  body.has-answer #sys dl, body.viewing #sys dl { display: none; }
}
/* 가로 태블릿(아이패드 가로): 답 칸 너비를 조금 더 */
@media (pointer: coarse) and (orientation: landscape) and (min-height: 600px) {
  #panel { left: max(var(--gut), calc(50vw - 520px)); right: max(var(--gut), calc(50vw - 520px)); }
}

/* 유튜브·웹 "열기" 단추 */
#viewBody .ytopen { margin-top: 2vh; padding: .8em 1.6em; border: 1px solid rgb(var(--c)); border-radius: 12px; color: var(--ink); text-decoration: none; background: rgba(var(--c), .18); font-size: 17px; }
#viewBody .ytwait span { overflow-wrap: anywhere; }

/* 화면 꺼짐 막기 안내 (phone.js) */
#keepOn { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar, 70px) + 8px); z-index: 7; font: 13px var(--sans); color: var(--dim);
  background: rgba(3, 8, 22, .9); border: 1px solid var(--faint); border-radius: 10px; padding: 6px 12px; pointer-events: none; opacity: 0; transition: opacity .4s; }
#keepOn.show { opacity: 1; }

/* 로그인 화면: 주인용 열쇠 칸은 접어 둠 */
#setup details { display: flex; flex-direction: column; gap: 10px; }
#setup details > summary { cursor: pointer; color: var(--dim); font-size: 14px; list-style: none; }
#setup details > summary::before { content: '▸ '; }
#setup details[open] > summary::before { content: '▾ '; }
#setup details[open] > label { margin-top: 8px; }
#setup details[hidden], #setup [hidden] { display: none !important; } /* 인터넷 접속자에게는 주인 칸을 아예 그리지 않음 */
#setup details { border-top: 1px solid var(--faint); padding-top: 12px; }
