/* Mobile-only UX corrections. Desktop styles stay in index.html. */
.mobile-menu-trigger,
.mobile-header-menu,
.mobile-modal-dismiss {
  display: none;
}

@media (max-width: 768px) {
  :root {
    --mobile-header-h: calc(56px + env(safe-area-inset-top));
    --mobile-footer-h: calc(48px + env(safe-area-inset-bottom));
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.app-mode,
  .app-shell {
    height: var(--mobile-viewport-height, 100dvh);
    min-height: 0;
  }

  /* Landing: keep a primary action in the first viewport. */
  .landing-nav {
    height: calc(62px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
  }

  .landing-navlinks {
    display: flex;
    margin-left: auto;
  }

  .landing-navlinks .landing-link {
    display: none;
  }

  .landing-nav .landing-mini-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 14px;
  }

  .landing-hero > section {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .landing-eyebrow { order: 1; }
  .landing-h1 { order: 2; }
  .landing-lead { order: 3; }
  .landing-actions {
    order: 4;
    margin-top: 22px;
  }
  .landing-promise {
    order: 5;
    margin-top: 24px;
  }
  .landing-platforms { order: 6; }

  .landing-business {
    gap: 6px 10px;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
    font-size: 12px;
    line-height: 1.55;
  }

  .landing-business a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 2px;
  }

  /* App shell: remove the late 390px fixed width and use one vertical scroller. */
  .app-shell > header {
    position: relative;
    z-index: 610;
    height: var(--mobile-header-h);
    flex: 0 0 var(--mobile-header-h);
    padding: env(safe-area-inset-top) 62px 0 12px;
    gap: 8px;
  }

  .app-shell > header > #btnCharge,
  .app-shell > header > #btnMyTools,
  .app-shell > header > #btnFeedback,
  .app-shell > header > #btnLogin,
  .app-shell > header > #btnLogout {
    display: none !important;
  }

  .app-shell .trial-badge {
    flex: 0 1 auto;
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border: 1px solid #d8e5e3;
    border-radius: 12px;
    background: #fff;
    color: #101828;
    font-size: 22px;
    font-weight: 900;
    line-height: 1;
  }

  .mobile-header-menu {
    position: fixed;
    top: calc(var(--mobile-header-h) + 8px);
    right: 12px;
    z-index: 620;
    width: min(236px, calc(100vw - 24px));
    gap: 4px;
    padding: 8px;
    border: 1px solid #d8e5e3;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .2);
  }

  .mobile-header-menu.open {
    display: grid;
  }

  .mobile-header-menu button {
    min-height: 46px;
    padding: 0 14px;
    border-radius: 11px;
    color: #101828;
    font-size: 14px;
    font-weight: 800;
    text-align: left;
  }

  .mobile-header-menu button:hover,
  .mobile-header-menu button:focus-visible {
    background: #e9fbf4;
    color: #087a59;
    outline: none;
  }

  .main,
  .left,
  .right {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .left {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: 24px;
  }

  .tools-grid,
  .chat {
    flex: 0 0 auto;
    overflow: visible;
  }

  .inputbox textarea {
    width: 100%;
    min-width: 0;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  textarea,
  select {
    font-size: 16px !important;
  }

  .attach-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .send {
    width: auto;
    height: 48px;
    min-width: 104px;
  }

  .starter-clear,
  .attach-item button {
    min-width: 36px;
    width: 36px;
    height: 36px;
  }

  .template-tab,
  .workspace-mode-new,
  .profile-card button,
  .pbtn,
  .vbtn,
  .ti-open,
  .ti-app,
  .ti-share,
  .ti-del {
    min-height: 44px;
  }

  /* Keep progress visible and abbreviate crowded preview actions. */
  .preview-head {
    height: auto;
    min-height: 58px;
    padding: 6px 10px;
    gap: 8px;
  }

  .preview-head .spacer {
    display: none;
  }

  .preview-title {
    display: block !important;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: #475467;
    font-size: 12.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #btnNew,
  #btnInstallApp {
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 0;
  }

  #btnNew::after {
    content: "＋ 새 도구";
    font-size: 12px;
  }

  #btnInstallApp::after {
    content: "📲 설치";
    font-size: 12px;
  }

  .empty {
    overflow-y: auto;
  }

  /* Compact, tappable legal footer in app mode. */
  body.app-mode .site-footer {
    height: var(--mobile-footer-h);
    flex: 0 0 var(--mobile-footer-h);
    padding: 0 10px env(safe-area-inset-bottom);
    overflow: visible;
    font-size: 11px;
    white-space: normal;
  }

  body.app-mode .site-footer > span:not(:last-child) {
    display: none;
  }

  body.app-mode .site-footer > span:last-child {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  body.app-mode .site-footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 2px;
  }

  /* Mobile sheets remain usable when the software keyboard is open. */
  .overlay {
    align-items: flex-end;
    padding: calc(12px + env(safe-area-inset-top)) 0 0;
    z-index: 700;
  }

  .modal {
    position: relative;
    width: 100%;
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 12px - env(safe-area-inset-top));
    padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    overscroll-behavior: contain;
  }

  .mobile-modal-dismiss {
    position: sticky;
    top: 0;
    z-index: 4;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 0 0 2px auto;
    border: 1px solid #d8e5e3;
    border-radius: 12px;
    background: #fff;
    color: #475467;
    font-size: 24px;
    line-height: 1;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .1);
  }

  .modal > .mobile-modal-dismiss {
    display: flex;
  }

  .vbar {
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 8px 0;
    gap: 6px;
  }

  .vbar .vtitle {
    min-width: 0;
  }

  .vbtn {
    padding: 0 9px;
    font-size: 12px;
  }

  .toast {
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 2147483647;
    width: max-content;
    max-width: calc(100vw - 24px);
    padding: 12px 16px;
    border-radius: 14px;
    line-height: 1.45;
    text-align: center;
  }

  body:not(.app-mode) #__mlt {
    top: calc(70px + env(safe-area-inset-top)) !important;
    right: 12px !important;
    width: 44px !important;
    height: 36px !important;
    padding: 0 !important;
  }

  body.app-mode #__mlt {
    top: calc(12px + env(safe-area-inset-top)) !important;
    right: 10px !important;
    width: 44px !important;
    height: 32px !important;
    padding: 0 !important;
    z-index: 630 !important;
  }

  .viewer.on ~ #__mlt {
    display: none !important;
  }
}

@media (max-width: 768px) and (max-height: 700px) {
  .empty-preview {
    display: none;
  }

  .empty {
    padding: 20px 18px;
  }
}
