/*
 * Mobile-first shell for noVNC (all screen sizes).
 * Layers: container 0 < connect card 20 < bar 30 < touch dot/HUD 34-36
 *         < sheet 40 < transition 50 < password 60 < status 100.
 * --app-h / --app-top come from visualViewport (app/mobile.js), so the
 * toolbar stays above the on-screen keyboard.
 */
:root {
  --app-h: 100dvh;
  --app-top: 0px;
  --bar: 60px;
  --rail: 76px;
  --bar-total: 0px;          /* bottom space taken by the toolbar */
  --rail-total: 0px;         /* right space taken by the landscape rail */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --bg: #16191c;
  --surface: #22272b;
  --surface-2: #2c3338;
  --line: #48525a;
  --text: #eef2f4;
  --muted: #b4c0c8;
  --accent: #8fe3cf;
  --accent-ink: #0e3a30;
  --danger: #f08a80;
  color-scheme: dark;
}
:root.noVNC_connected { --bar-total: calc(var(--bar) + var(--safe-b)); }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
body {
  font: 16px/1.45 system-ui, -apple-system, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

/* The legacy control bar stays in the DOM for app/ui.js but is never shown. */
#noVNC_control_bar_anchor { display: none !important; }

/* ----- remote screen ----- */
#noVNC_container {
  position: fixed;
  z-index: 0;
  top: calc(var(--app-top) + var(--safe-t));
  left: var(--safe-l);
  right: calc(var(--safe-r) + var(--rail-total));
  width: auto;
  height: calc(var(--app-h) - var(--safe-t) - var(--bar-total));
  border-radius: 0;
  background: #0e1012;
  touch-action: none;
  overflow: hidden;
}
#noVNC_container > div { background-color: #0e1012 !important; }
#noVNC_container canvas { touch-action: none; }
:root.m-view-only #noVNC_container::after {
  content: "보기 전용";
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .7);
  color: #ffe08a;
  font-size: 13px;
  pointer-events: none;
}

/* Receives the phone keyboard. Must stay focusable, so not display:none. */
#noVNC_keyboardinput {
  display: block;
  position: fixed;
  left: 0;
  top: var(--app-top);
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: .01;
  font-size: 16px;   /* avoids focus zoom on iOS */
  caret-color: transparent;
  background: transparent;
  color: transparent;
  z-index: 0;
  pointer-events: none;
  resize: none;
}

/* ----- connect card (must stay above the fixed container; see RESULT.md) ----- */
#m-connect-layer {
  z-index: 20;
  top: var(--app-top);
  height: var(--app-h);
  padding: 12px;
  box-sizing: border-box;
  align-items: safe center;
}
.noVNC_center.noVNC_connect_layer { z-index: 60; }
#noVNC_connect_dlg {
  box-sizing: border-box;
  width: min(380px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  transform: scale(.96);
}
#noVNC_connect_dlg.noVNC_open { transform: none; }
#noVNC_connect_dlg h1 { margin: 0 0 4px; font-size: 22px; }
#noVNC_connect_dlg p { margin: 0 0 12px; }
.m-muted { color: var(--muted); font-size: 14px; }
.m-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(240, 138, 128, .14);
  border: 1px solid var(--danger);
  color: #ffd9d4;
  font-size: 15px;
}
#m-connect-advanced { margin-top: 12px; color: var(--muted); font-size: 14px; }
#m-connect-advanced summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
#m-connect-url { word-break: break-all; }

button, .m-primary, .m-secondary, .m-danger {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}
#noVNC_connect_button.m-primary, #m-sheet button, #noVNC_transition button, #m-noframe button {
  box-sizing: border-box;
  min-height: 48px;
  min-width: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: none;
}
#noVNC_connect_button.m-primary {
  display: block;
  width: 100%;
  min-height: 56px;
  margin: 4px 0 12px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 19px;
}
.m-danger { color: #ffd9d4 !important; border-color: var(--danger) !important; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, summary:focus-visible, input:focus-visible + span, .m-check input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.m-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 15px;
  cursor: pointer;
}
.m-check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }

/* ----- status banner, transition, password ----- */
#noVNC_status {
  top: calc(var(--app-top) + var(--safe-t));
  right: var(--rail-total);   /* never cover the landscape rail */
  width: auto;
  box-sizing: border-box;
  min-height: 48px;
  padding: 10px max(16px, var(--safe-r)) 10px max(16px, var(--safe-l));
  align-items: center;
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
}
#noVNC_status::before { flex: none; }
#noVNC_transition {
  z-index: 50;
  gap: 18px;
  background: rgba(14, 16, 18, .88);
  font-size: 18px;
}
#noVNC_transition > div:last-child { display: flex; gap: 12px; }
:root:not(.noVNC_connecting) #m-cancel-connect { display: none; }
#noVNC_cancel_reconnect_button { min-height: 48px; font-size: 16px; }
#noVNC_password_dlg {
  width: min(340px, calc(100vw - 32px));
  box-sizing: border-box;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
#noVNC_password_dlg li { margin-bottom: 12px; }
#noVNC_password_dlg label { display: block; margin-bottom: 6px; }
#noVNC_password_input { box-sizing: border-box; width: 100%; min-height: 48px; font-size: 16px; }
#noVNC_password_button { width: 100%; min-height: 48px; font-size: 16px; }

/* ----- primary toolbar ----- */
#m-bar {
  display: none;
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(var(--app-top) + var(--app-h) - var(--bar-total));
  height: var(--bar-total);
  box-sizing: border-box;
  padding: 6px max(6px, var(--safe-r)) calc(6px + var(--safe-b)) max(6px, var(--safe-l));
  gap: 4px;
  grid-template-columns: repeat(6, minmax(44px, 1fr));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
:root.noVNC_connected #m-bar { display: grid; }
#m-bar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  min-height: 48px;
  padding: 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
#m-bar button span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#m-bar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#m-bar svg .m-fill { fill: currentColor; stroke: none; }
#m-bar button:active { background: var(--surface-2); }
#m-bar button[aria-pressed="true"], #m-bar button[aria-expanded="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ----- feedback ----- */
#m-hud {
  position: fixed;
  z-index: 35;
  /* above the toolbar, clear of the top status banner */
  top: calc(var(--app-top) + var(--app-h) - var(--bar-total) - 56px);
  left: calc((100vw - var(--rail-total)) / 2);
  transform: translateX(-50%);
  max-width: calc(100vw - var(--rail-total) - 32px);
  box-sizing: border-box;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}
#m-noframe {
  position: fixed;
  z-index: 36;
  left: 50%;
  top: calc(var(--app-top) + var(--safe-t) + 64px);
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--danger);
  font-size: 15px;
}
#m-touch-dot {
  position: fixed;
  z-index: 34;
  left: -20px;
  top: -20px;
  width: 40px;
  height: 40px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 3px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
#m-touch-dot.m-show { animation: m-dot .45s ease-out; }
#m-touch-dot.m-right { border-color: #ffb36b; }
@keyframes m-dot {
  from { opacity: 1; scale: .5; }
  to { opacity: 0; scale: 1.2; }
}

/* ----- secondary sheet ----- */
#m-sheet {
  position: fixed;
  z-index: 40;
  left: max(0px, var(--safe-l));
  right: max(0px, var(--safe-r));
  bottom: calc(100% - var(--app-top) - var(--app-h) + var(--bar-total));
  max-height: calc(var(--app-h) - var(--bar-total) - var(--safe-t) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 0 16px 20px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
  touch-action: pan-y;
}
#m-sheet header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0 12px;
  margin: 0 -16px;
  padding: 12px 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
#m-sheet h2 { margin: 0; font-size: 18px; }
#m-state { grid-column: 1; margin: 0; color: var(--muted); font-size: 14px; }
#m-sheet-close { grid-column: 2; grid-row: 1 / span 2; }
#m-sheet h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
#m-sheet p { margin: 8px 0; }
.m-row { display: flex; flex-wrap: wrap; gap: 8px; }
.m-row > button { flex: 1 1 0; }
#m-sheet .m-keys > button { flex: 1 0 64px; min-width: max-content; padding: 6px 8px; font-size: 15px; }
#m-sheet button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.m-help { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.m-help li { margin: 4px 0; }
.m-help b { color: var(--text); }
.m-seg { display: flex; gap: 0; margin: 12px 0 0; padding: 0; border: 0; }
.m-seg legend { padding: 0 0 6px; font-size: 14px; color: var(--muted); }
.m-seg label { flex: 1; cursor: pointer; }
.m-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.m-seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.m-seg label:first-of-type span { border-radius: 12px 0 0 12px; }
.m-seg label:last-of-type span { border-radius: 0 12px 12px 0; }
.m-seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.m-seg input:disabled + span { opacity: .4; }
#m-text {
  box-sizing: border-box;
  width: 100%;
  min-height: 84px;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #111;
  font: 16px/1.5 inherit;
  font-family: inherit;
}
#m-text:disabled { background: #555; }

/* ----- phone landscape: toolbar becomes a right-hand rail ----- */
@media (orientation: landscape) and (max-height: 540px) {
  :root.noVNC_connected { --bar-total: 0px; --rail-total: var(--rail); }
  #m-bar {
    top: var(--app-top);
    left: auto;
    right: 0;
    height: var(--app-h);
    width: calc(var(--rail) + var(--safe-r));
    padding: max(4px, var(--safe-t)) calc(4px + var(--safe-r)) max(4px, var(--safe-b)) 4px;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(6, minmax(44px, 1fr));
    border-top: 0;
    border-left: 1px solid var(--line);
  }
  #m-bar button { min-height: 44px; font-size: 11px; }
  #m-bar svg { width: 22px; height: 22px; }
  #m-sheet {
    top: var(--app-top);
    bottom: auto;
    left: auto;
    right: calc(var(--rail) + var(--safe-r));
    width: min(420px, 64vw);
    height: var(--app-h);
    max-height: none;
    border: 1px solid var(--line);
    border-radius: 0;
  }
}

/* ----- large screens with a mouse: compact centred toolbar, side sheet ----- */
@media (min-width: 900px) and (min-height: 541px) {
  :root { --bar: 58px; }
  #m-bar { grid-template-columns: repeat(6, 104px); justify-content: center; }
  #m-sheet {
    left: auto;
    right: 16px;
    width: 420px;
    border-radius: 16px;
    border-bottom: 1px solid var(--line);
    bottom: calc(100% - var(--app-top) - var(--app-h) + var(--bar-total) + 12px);
  }
}
