

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; }
button, input, select, textarea { max-width: 100%; }
a, button, input, select, textarea { touch-action: manipulation; }

@media (max-width: 760px) {
  .site-topbar {
    padding: 9px 12px;
    gap: 8px;
  }
  .site-topbar .stb-brand {
    font-size: .92rem;
    gap: 6px;
  }
  .site-topbar .stb-brand .stb-mono,
  .site-topbar .stb-brand .stb-logo {
    width: 28px;
    height: 28px;
  }
  .site-topbar .stb-right {
    gap: 8px;
  }
  .site-topbar .stb-link {
    font-size: .94rem;
  }

  
  .lock-wrap { padding: 72px 12px 24px; }
  .lock-card { padding: 32px 20px 26px; }
  .lock-card input, .lock-btn { font-size: 1rem; }

  
  .layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 14px 10px 34px;
  }
  .sidebar {
    width: 100% !important;
    max-width: none !important;
    flex: none !important;
    min-height: 0 !important;
    position: static !important;
    padding: 10px !important;
    border-radius: 12px;
  }
  .org-switch {
    margin-bottom: 8px;
    padding: 9px 10px;
  }
  .org-avatar { width: 34px; height: 34px; }
  .org-name { font-size: .9rem; }
  .nav-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .nav-item {
    min-width: 0;
    gap: 8px;
    padding: 10px 9px;
    font-size: .96rem;
  }
  .nav-item .nav-ico { width: 18px; font-size: .98rem; }
  .sidebar-spacer { display: none; }
  .sidebar-bottom {
    margin-top: 8px;
    padding-top: 7px;
  }
  .sidebar-bottom .nav-item { width: 100%; }

  .main,
  .main-wrap {
    width: 100%;
    min-width: 0;
  }
  .main {
    padding: 18px 14px !important;
    border-radius: 10px;
  }
  .main-wrap {
    display: flex !important;
    flex-direction: column;
    gap: 14px;
  }
  .main-head {
    gap: 7px;
    margin-bottom: 15px;
  }
  .main-head h1,
  .main h1 { font-size: 1.45rem; }
  .main .sub { font-size: 1rem; }

  
  .preview-col {
    position: static !important;
    order: -1;
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
  }
  .theme-grid,
  .icon-grid,
  .background-grid,
  .kee-v42-purpose-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .profile-row,
  .slug-row,
  .pin-row,
  .toggle-row,
  .row-date,
  .row-title,
  .row-note {
    grid-template-columns: 1fr !important;
    display: grid;
    gap: 8px;
  }
  .section,
  .section-title,
  .section-sub { max-width: 100%; }
  .section { overflow: hidden; }
  input, select, textarea {
    min-width: 0;
    font-size: 16px !important; 
  }

  
  .editor-wrap {
    display: flex !important;
    flex-direction: column;
    gap: 14px;
  }
  .controls-panel {
    width: 100%;
    min-width: 0;
    order: 2;
  }
  .editor-wrap > * {
    min-width: 0;
    max-width: 100%;
  }
  .customizer-tools {
    position: sticky;
    top: 0;
    gap: 6px;
    flex-wrap: wrap;
    padding: 3px 0 8px;
  }
  .customizer-search { width: 100%; flex: 1 1 100%; }
  .icon-grid { gap: 7px; }
  .sticker-row,
  .bg-preview,
  .save-row {
    flex-wrap: wrap;
  }
  .background-preview {
    width: 100%;
    max-width: 100%;
    min-height: 250px;
  }
  .preview-book {
    max-width: 130px;
  }

  
  .action-row,
  .chip-row {
    flex-wrap: wrap;
    gap: 7px;
  }
  .action-row > *,
  .row-actions > * { max-width: 100%; }
  .book-card,
  .entry-card,
  .stat-card {
    max-width: 100%;
  }

  
  .stat-row {
    grid-template-columns: 1fr !important;
  }
  .role-edit-row,
  .row-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .admin-table-wrap,
  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 560px; }

  
  .search-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .page-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  
  .write-layout,
  .editor-layout {
    width: 100%;
    max-width: 100%;
  }
  .preview-shell {
    position: static !important;
    width: 100%;
    max-width: 100%;
    order: -1;
  }
  .file-row,
  .back-link-row,
  .sticker-control-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .page-sticker-tools { overflow: hidden; }
  .page-sticker-palette,
  .page-sticker-list { gap: 6px; }

  
  .stage {
    width: 100%;
    max-width: 100%;
  }
  .cover {
    max-width: 100%;
  }
  .book {
    max-width: 100%;
  }
  .controls {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 7px;
  }
  .nav-btn {
    min-height: 42px;
    white-space: nowrap;
  }
  .pin-gate {
    width: 100%;
    max-width: 420px;
    padding: 30px 18px;
  }
  .pin-gate form {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .pin-gate input,
  .pin-gate button { width: 100%; }

  
  .wrap {
    width: 100%;
    max-width: 100%;
    margin: 16px auto;
    padding: 0 10px;
  }
  .card {
    padding: 22px 16px !important;
  }
  .gift {
    display: block !important;
    overflow-wrap: anywhere;
  }
  .gift form { margin-top: 10px; }
  .gift .btn { width: 100%; }

  
  .nav { padding: 16px 12px; }
  .brand { font-size: 1.02rem; }
  .nav-actions { gap: 7px; }
  .nav-actions a:not(.start) { display: none; }
  .hero { width: 100%; }
  .actions .btn { flex: 1 1 140px; text-align: center; }
}

@media (max-width: 480px) {
  .site-topbar .stb-right .stb-link[href="/dashboard"],
  .site-topbar .stb-right .stb-link[href="/logout"] {
    font-size: .86rem;
  }
  .layout { padding-left: 7px; padding-right: 7px; }
  .sidebar { padding: 8px !important; }
  .nav-list { grid-template-columns: 1fr 1fr; }
  .nav-item { font-size: .9rem; padding: 9px 7px; }
  .main { padding: 15px 11px !important; }
  .theme-grid,
  .icon-grid,
  .background-grid,
  .kee-v42-purpose-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .cover {
    width: 94vw !important;
  }
  .book {
    width: 96vw !important;
  }
  .page { padding-left: 20px !important; padding-right: 20px !important; }
}

@media (max-width: 360px) {
  .nav-list { grid-template-columns: 1fr; }
  .site-topbar .stb-link { font-size: .82rem; }
  .cover { width: 96vw !important; }
}


@media (max-width: 720px) {
  
  .editor-wrap {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    width: 100% !important;
  }

  .editor-wrap .cover-stage {
    position: relative !important;
    top: auto !important;
    order: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 4px 0 12px !important;
    background: transparent !important;
    z-index: 1 !important;
  }

  .editor-wrap .cover {
    width: min(72vw, 255px) !important;
    max-width: 255px !important;
    max-height: none !important;
    margin: 0 auto !important;
    padding: 28px 18px 24px !important;
    border-radius: 12px !important;
  }

  .editor-wrap .cover h2 {
    max-width: 88%;
    font-size: 1.45rem !important;
    line-height: 1.15;
    margin: 13px 0 4px !important;
    overflow-wrap: anywhere;
  }

  .editor-wrap .cover .tag {
    max-width: 88%;
    font-size: 1rem !important;
    overflow-wrap: anywhere;
  }

  .editor-wrap .mono {
    width: 48px !important;
    height: 48px !important;
    font-size: 1.35rem !important;
  }

  .editor-wrap .controls-panel {
    order: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .editor-wrap .customizer-tools {
    position: relative !important;
    top: auto !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 7px !important;
    margin-bottom: 9px !important;
    padding: 0 !important;
    background: transparent !important;
    z-index: 1 !important;
  }

  .editor-wrap .customizer-search {
    width: 100% !important;
    min-width: 0 !important;
    padding: 11px 12px !important;
  }

  .editor-wrap .quick-jump {
    width: 100% !important;
    margin: 0 0 9px !important;
    padding-bottom: 3px !important;
  }

  .editor-wrap .quick-jump button {
    min-height: 36px;
    padding: 7px 11px !important;
    white-space: nowrap;
  }

  .editor-wrap .mobile-editor-note {
    margin: 0 0 11px !important;
    line-height: 1.35;
  }

  .editor-wrap .section {
    width: 100% !important;
    margin-bottom: 11px !important;
    padding: 14px !important;
    border-radius: 10px !important;
    overflow: hidden !important;
  }

  .editor-wrap .section-title {
    min-height: 30px;
    font-size: 1rem !important;
    line-height: 1.25;
  }

  .editor-wrap .section-sub {
    font-size: .88rem !important;
    line-height: 1.35;
    margin-bottom: 11px !important;
  }

  
  .editor-wrap .icon-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .editor-wrap .icon-option {
    min-width: 0 !important;
    min-height: 74px !important;
    padding: 9px 5px !important;
    gap: 5px !important;
    border-radius: 9px !important;
    font-size: .82rem;
  }

  .editor-wrap .icon-preview {
    font-size: 25px !important;
  }

  
  .editor-wrap .theme-grid,
  .editor-wrap .background-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .editor-wrap .theme-option,
  .editor-wrap .background-option {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 58px;
  }

  .editor-wrap .theme-name,
  .editor-wrap .bg-name,
  .editor-wrap .bg-desc {
    overflow-wrap: anywhere;
  }

  .editor-wrap .background-preview {
    width: 100% !important;
    min-height: 190px !important;
    margin-top: 10px;
  }

  .editor-wrap .background-controls {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .editor-wrap .background-controls label {
    display: grid;
    gap: 5px;
    width: 100%;
  }

  .editor-wrap .background-controls input[type="range"],
  .editor-wrap .background-controls select {
    width: 100% !important;
    min-width: 0 !important;
  }

  
  .editor-wrap .stickers {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }

  .editor-wrap .sticker-btn {
    min-width: 0 !important;
    min-height: 48px;
    padding: 8px 7px !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .editor-wrap .sticker-tools {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 9px !important;
    align-items: center !important;
  }

  .editor-wrap .sticker-tools label {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 7px;
  }

  .editor-wrap .sticker-tools input[type="range"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  .editor-wrap .upload-sticker-btn {
    grid-column: 1 / -1;
    width: 100% !important;
  }

  .editor-wrap .selected-list {
    max-height: none !important;
    overflow: visible !important;
  }

  .editor-wrap .sticker-row {
    min-width: 0;
    flex-wrap: wrap;
  }

  .editor-wrap .sticker-row .meta {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .editor-wrap .save-row {
    margin-top: 4px !important;
    padding-top: 14px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
  }

  .editor-wrap .save-row .btn,
  .main > .save-row .btn {
    width: 100% !important;
    min-height: 46px;
  }
}

@media (max-width: 390px) {
  .editor-wrap .cover {
    width: min(70vw, 230px) !important;
    max-width: 230px !important;
  }

  .editor-wrap .icon-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .editor-wrap .icon-option {
    min-height: 70px !important;
  }

  .editor-wrap .sticker-tools {
    grid-template-columns: 1fr !important;
  }

  .editor-wrap .upload-sticker-btn {
    grid-column: auto;
  }
}


/* Global mobile polish */
@media (max-width:760px){
  html,body{max-width:100%;overflow-x:hidden;}
  img,video,canvas,svg{max-width:100%;}
  button,input,select,textarea{max-width:100%;}
}
