/* ============================================================
   Fyona — Mobile Responsive Overrides
   All rules inside @media queries — desktop is untouched.
   ============================================================ */

/* Keep mobile-only taskbar hidden on desktop by default. */
.mobile-taskbar {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* ----------------------------------------------------------
   1. TABLET  (max-width: 1024px)
   ---------------------------------------------------------- */
@media (max-width: 1024px) {

  /* ---- Templates — relax grid ---- */
  .templates-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .templates-grid .template-card {
    width: auto;
  }

  /* ---- Phiona — collapse sidebar ---- */
  .phiona-portal {
    grid-template-columns: 1fr;
    padding: 40px 32px 80px;
  }

  .phiona-nav {
    position: static;
    min-height: auto;
  }

  .phiona-studio {
    grid-template-columns: 1fr;
  }

  /* ---- Arcana — reduce padding ---- */
  .arcana {
    padding: 40px 32px 80px;
  }

  /* ---- Pricing — hero panel padding ---- */
  .pricing-hero-panel {
    padding: 24px;
  }

  .pricing-compare-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ----------------------------------------------------------
   2. PHONE  (max-width: 768px)
   ---------------------------------------------------------- */
@media (max-width: 768px) {

  /* ============ Global ============ */
  body {
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .btn {
    min-height: 44px;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .lead {
    font-size: 0.95rem;
  }

  img, iframe, video, canvas, svg {
    max-width: 100%;
    height: auto;
  }

  /* ============ Site header / nav ============ */
  .site-nav,
  .site-auth {
    display: none;
  }

  .mobile-taskbar {
    display: flex !important;
    pointer-events: auto !important;
    visibility: visible !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 905;
    align-items: flex-start;
    justify-content: space-around;
    gap: 0;
    height: calc(62px + env(safe-area-inset-bottom, 0px));
    padding: 6px max(10px, env(safe-area-inset-left, 0px)) max(4px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-right, 0px));
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(18px) saturate(170%);
    border-top: 1px solid rgba(27, 27, 27, 0.1);
    box-shadow: 0 -4px 20px rgba(12, 15, 20, 0.08);
  }

  .mobile-taskbar-item {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: rgba(27, 27, 27, 0.62);
    text-decoration: none;
    font-family: "Space Grotesk", "Manrope", system-ui, -apple-system, sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: color 0.15s ease, transform 0.15s ease;
  }

  .mobile-taskbar-item::before {
    content: attr(data-icon);
    font-size: 17px;
    line-height: 1;
  }

  .mobile-taskbar-item:active {
    transform: scale(0.96);
  }

  .mobile-taskbar-item.is-active {
    color: var(--accent);
  }

  .mobile-taskbar-item.is-disabled {
    opacity: 0.45;
    pointer-events: none;
  }

  body:not(.is-editor) main {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  }

  .brand {
    font-size: 1.35rem;
  }

  /* ============ Usage page ============ */
  .usage-hero {
    display: flex;
    flex-direction: column;
  }

  .usage-backdrop {
    display: none;
  }

  .usage-hero .btn,
  .usage-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .usage-actions {
    flex-direction: column;
  }

  .usage-grid {
    grid-template-columns: 1fr;
  }

  .usage-overview {
    grid-template-columns: 1fr;
  }

  .usage-panels {
    grid-template-columns: 1fr;
  }

  .usage-card,
  .usage-panel {
    padding: 20px;
  }

  .usage-faq {
    grid-template-columns: 1fr;
  }

  .usage-embed-code textarea {
    font-size: 0.8rem;
  }

  .usage-hero-meta {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .usage-inline-actions {
    flex-wrap: wrap;
  }

  .usage-inline-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .usage-meta {
    grid-template-columns: 1fr;
  }

  /* ============ Templates page ============ */
  .templates-hero {
    grid-template-columns: 1fr;
  }

  .templates-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .templates-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 4px;
  }

  .templates-tab {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .templates-search {
    width: 100%;
  }

  .templates-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .templates-grid .template-card {
    width: auto;
  }

  .template-card {
    min-height: auto;
    height: auto;
  }

  .template-card-header {
    flex-wrap: wrap;
  }

  .template-form {
    flex-direction: column;
    width: 100%;
  }

  .template-form input,
  .template-form button {
    width: 100%;
    min-width: 0;
  }

  .templates-hero-panel {
    padding: 24px;
  }

  /* ============ Projects page ============ */
  .projects {
    padding: 32px 20px 64px;
  }

  .projects-hero {
    grid-template-columns: 1fr;
  }

  .project-form {
    flex-direction: column;
  }

  .project-form input,
  .project-form select,
  .project-form button {
    width: 100%;
  }

  .projects-list-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .project-grid {
    grid-template-columns: 1fr;
  }

  /* Project modals */
  .project-modal-overlay {
    padding: 16px;
  }

  .project-modal {
    width: 100%;
    max-width: none;
    border-radius: 20px;
  }

  .project-modal-body input[type="text"] {
    font-size: 16px; /* prevent iOS zoom */
  }

  .project-dropdown {
    min-width: 140px;
  }

  .project-dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Generic modals (fallback) */
  .modal-content {
    width: calc(100% - 32px);
    max-width: none;
    margin: auto 16px;
  }

  .modal-content input,
  .modal-content select,
  .modal-content textarea {
    font-size: 16px;
  }

  /* ============ Checkout / Login / Signup ============ */
  .checkout {
    padding: 32px 20px 64px;
  }

  .checkout-hero {
    grid-template-columns: 1fr;
  }

  .checkout-method-tabs {
    flex-direction: column;
  }

  .checkout-tab {
    min-height: 44px;
  }

  .checkout-fields input,
  .checkout-fields select {
    font-size: 16px;
  }

  .checkout-actions {
    flex-direction: column;
  }

  .checkout-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .checkout-stripe-cards {
    flex-wrap: wrap;
  }

  .checkout-panel {
    gap: 16px;
  }

  .checkout-summary-header {
    flex-wrap: wrap;
  }

  .checkout-price {
    font-size: 1.8rem;
  }

  /* ============ Verify page ============ */
  .verify-card {
    padding: 28px 20px;
  }

  .verify-card h1 {
    font-size: 1.4rem;
  }

  .verify-form input {
    font-size: 16px;
    letter-spacing: 0.35em;
  }

  .verify-actions {
    flex-direction: column;
  }

  .verify-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ============ About page (supplements existing 720px rules) ============ */
  .about-section {
    gap: 24px;
  }

  .about-grid {
    grid-template-columns: 1fr;
  }

  .about-hero h1 {
    font-size: 2rem;
  }

  .about-callout {
    flex-direction: column;
    gap: 16px;
  }

  .about-callout .btn {
    width: 100%;
    justify-content: center;
  }

  .about-pill-row {
    gap: 8px;
  }

  .about-world-card {
    padding: 20px;
  }

  .about-timeline-item {
    padding: 16px;
  }

  .about-value,
  .about-leader {
    padding: 20px;
  }

  .about-trust {
    padding: 20px;
  }

  .about-logos {
    gap: 8px;
    justify-content: center;
  }

  /* ============ Pricing page (supplements existing 768px rules) ============ */
  .pricing-hero {
    grid-template-columns: 1fr;
  }

  .pricing-hero-panel {
    padding: 22px;
  }

  .pricing-toggles {
    align-items: stretch;
  }

  .billing-toggle,
  .currency-toggle {
    justify-content: center;
  }

  .pricing-card {
    padding: 22px;
  }

  .pricing-card:hover {
    transform: none;
  }

  .tier-control {
    gap: 12px;
  }

  .tier-credits-hero {
    font-size: 2rem;
  }

  .tier-price-row {
    flex-wrap: wrap;
  }

  .pricing-cta-card {
    padding: 24px 20px;
  }

  .pricing-cta-card .btn {
    width: 100%;
    justify-content: center;
  }

  /* ============ Legal / TOS / Privacy ============ */
  .legal {
    padding: 28px 20px;
  }

  .legal h1 {
    font-size: 1.8rem;
  }

  .legal-pages {
    grid-template-columns: 1fr;
  }

  .legal-page {
    padding: 20px;
  }

  .legal-agreement-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  /* ============ Phiona portal ============ */
  .phiona-portal {
    grid-template-columns: 1fr;
    padding: 32px 20px 64px;
  }

  .phiona-nav {
    position: static;
    min-height: auto;
    border-radius: 18px;
    padding: 16px;
  }

  .phiona-hero {
    padding: 22px;
  }

  .phiona-section {
    padding: 18px;
  }

  .phiona-studio {
    grid-template-columns: 1fr;
  }

  .phiona-studio-code {
    padding: 14px;
    border-radius: 14px;
  }

  .phiona-studio-code pre {
    font-size: 0.85rem;
  }

  .phiona-studio-panel {
    padding: 14px;
    border-radius: 14px;
  }

  .phiona-panel-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .phiona-step {
    padding: 14px;
  }

  .phiona-value {
    font-size: 1.6rem;
  }

  .phiona-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* ============ Arcana page ============ */
  .arcana {
    padding: 32px 20px 64px;
  }

  .arcana-hero {
    grid-template-columns: 1fr;
  }

  .arcana-hero-copy h1 {
    font-size: 2rem;
  }

  .arcana-hero-panel {
    padding: 22px;
    border-radius: 18px;
  }

  .arcana-hero-meta {
    gap: 12px;
  }

  .arcana-meta-block {
    min-width: 0;
  }

  .arcana-story {
    grid-template-columns: 1fr;
  }

  .arcana-story-card {
    padding: 20px;
  }

  .arcana-team-grid {
    grid-template-columns: 1fr;
  }

  .arcana-card {
    padding: 18px;
  }

  .arcana-details {
    font-size: 0.8rem;
  }

  /* ============ Home page (supplements existing rules) ============ */
  .feature-card {
    padding: 24px 20px;
  }

  .cta-panel {
    padding: 32px 20px;
  }

  .cta-panel .btn {
    width: 100%;
    justify-content: center;
  }

  /* ============ Editor mobile toolbar redesign ============ */
  .is-editor .editor {
    padding: 0;
    margin-top: 0;
    min-height: 100svh;
    height: 100svh;
    gap: 0;
    background: radial-gradient(circle at top left, rgba(255, 246, 235, 0.82) 0%, rgba(243, 230, 214, 0.56) 48%, rgba(234, 216, 199, 0.42) 100%);
  }

  .is-editor .mobile-toolbar {
    display: flex !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .is-editor .editor-pane {
    border-radius: 0;
    margin: 0;
    padding: 10px 10px 6px;
    min-height: calc(100svh - 130px - env(safe-area-inset-bottom, 0px));
    height: auto;
    max-height: none;
    overflow: auto;
    background: rgba(255, 255, 255, 0.86);
  }

  .is-editor .pane-title {
    margin: 0 2px 8px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(27, 27, 27, 0.62);
  }

  .is-editor .file-list {
    position: sticky;
    top: calc(max(60px, env(safe-area-inset-top, 0px)) + 8px);
    z-index: 31;
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(27, 27, 27, 0.1);
    box-shadow: 0 8px 20px rgba(27, 27, 27, 0.08);
    backdrop-filter: blur(10px);
  }

  .is-editor .file-list-title {
    margin-bottom: 6px;
    letter-spacing: 0.12em;
  }

  .is-editor .file-list ul {
    margin: 0;
    padding: 2px 0;
    list-style: none;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .is-editor .file-list ul::-webkit-scrollbar {
    display: none;
  }

  .is-editor .file-list li {
    margin: 0;
    flex: 0 0 auto;
  }

  .is-editor .file-list-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(246, 240, 232, 0.8);
    border: 1px solid rgba(27, 27, 27, 0.1);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
  }

  .is-editor .file-list li.active .file-list-item {
    background: rgba(217, 86, 60, 0.16);
    border-color: rgba(217, 86, 60, 0.45);
    color: var(--accent-dark);
  }

  .is-editor.mobile-files-collapsed .file-list {
    display: none;
  }

  .is-editor .code-pane,
  .is-editor .toolbox-pane,
  .is-editor .agent-pane {
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(27, 27, 27, 0.08);
    overflow: hidden;
  }

  .is-editor #latex-input {
    min-height: 240px;
    font-size: 15px;
    line-height: 1.5;
    padding: 4px;
  }

  .is-editor .toolbox-toolbar {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding: 10px;
    background: linear-gradient(135deg, rgba(247, 241, 232, 0.95) 0%, rgba(242, 233, 223, 0.78) 100%);
    border-bottom: 1px solid rgba(27, 27, 27, 0.1);
    scrollbar-width: none;
  }

  .is-editor .toolbox-toolbar::-webkit-scrollbar {
    display: none;
  }

  .is-editor .toolbox-tool {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 12px;
  }

  .is-editor .toolbox-mode-panel {
    position: sticky;
    top: 60px;
    z-index: 24;
    padding: 10px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid rgba(27, 27, 27, 0.08);
    gap: 10px;
  }

  .is-editor .toolbox-mode-title {
    font-size: 0.7rem;
  }

  .is-editor .toolbox-control input,
  .is-editor .toolbox-control select {
    min-height: 36px;
  }

  .is-editor .agent-tabs {
    position: sticky;
    top: 0;
    z-index: 25;
    margin: 0;
    padding: 8px;
    border-bottom: 1px solid rgba(27, 27, 27, 0.08);
    background: rgba(255, 255, 255, 0.92);
  }

  .is-editor .agent-tab-list {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    scrollbar-width: none;
  }

  .is-editor .agent-tab-list::-webkit-scrollbar {
    display: none;
  }

  .is-editor .agent-stream {
    padding: 12px;
    margin: 8px;
    min-height: 180px;
    border-radius: 12px;
  }

  .is-editor .agent-input {
    position: sticky;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 25;
    margin: 8px;
    padding: 8px;
    gap: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(27, 27, 27, 0.1);
    box-shadow: 0 8px 20px rgba(27, 27, 27, 0.08);
    backdrop-filter: blur(8px);
  }

  .is-editor .agent-input select,
  .is-editor .agent-input input,
  .is-editor .agent-input button {
    min-height: 42px;
  }

  .is-editor .editor-actions {
    position: sticky;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 24;
    margin-top: 6px;
    padding: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(27, 27, 27, 0.1);
    box-shadow: 0 8px 18px rgba(27, 27, 27, 0.07);
    backdrop-filter: blur(8px);
  }

  .is-editor .editor-actions .btn {
    width: 100%;
  }

  .is-editor .history-panel {
    border-radius: 0;
    padding: 12px;
    background: rgba(255, 255, 255, 0.98);
  }

  .is-editor.history-open .pane-title,
  .is-editor.history-open .file-list,
  .is-editor.history-open .toolbox-pane,
  .is-editor.history-open .toolbox-mode-panel,
  .is-editor.history-open .toolbox-sections,
  .is-editor.history-open .history-panel-header h2 {
    display: none !important;
  }

  .is-editor .mobile-taskbar {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }
}

/* ----------------------------------------------------------
   3. SMALL PHONE  (max-width: 480px)
   ---------------------------------------------------------- */
@media (max-width: 480px) {

  /* ============ Global ============ */
  .site-header {
    padding: 14px 16px;
  }

  .brand {
    font-size: 1.2rem;
  }

  /* Page containers — tighter side padding */
  .usage,
  .projects,
  .templates,
  .checkout,
  .arcana,
  .page.about {
    padding-left: 16px;
    padding-right: 16px;
  }

  .phiona-portal {
    padding: 24px 14px 64px;
  }

  /* ============ Usage page ============ */
  .usage-page {
    padding: 0 4px 40px;
  }

  .usage-card,
  .usage-panel {
    padding: 16px;
    border-radius: 16px;
  }

  .usage-stat {
    padding: 14px;
  }

  .usage-value {
    font-size: 1.6rem;
  }

  .usage-chip {
    width: 100%;
    text-align: center;
  }

  .usage-progress-label {
    gap: 10px;
    flex-direction: column;
    align-items: flex-start;
  }

  .usage-embed-code textarea {
    font-size: 0.75rem;
  }

  .usage-faq {
    gap: 12px;
  }

  /* ============ Templates page ============ */
  .templates-tab {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .templates-hero-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .templates-hero-title {
    font-size: 1.4rem;
  }

  .templates-hero-number {
    font-size: 1.2rem;
  }

  /* ============ Projects page ============ */
  .projects-hero-copy,
  .projects-hero-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .projects-hero h1 {
    font-size: 1.5rem;
  }

  .project-card {
    padding: 16px;
    border-radius: 12px;
  }

  .project-modal {
    border-radius: 18px;
    padding: 20px;
  }

  .project-modal-title {
    font-size: 1.1rem;
  }

  .project-confirm {
    padding: 12px;
    font-size: 0.85rem;
  }

  .project-confirm-btns .btn,
  .project-confirm-cancel,
  .project-confirm-delete {
    min-height: 44px;
  }

  /* ============ Checkout / Login / Signup ============ */
  .checkout-form,
  .checkout-summary {
    padding: 18px;
    border-radius: 18px;
  }

  .checkout-price {
    font-size: 1.6rem;
  }

  .checkout-panel-card {
    padding: 16px;
    border-radius: 16px;
  }

  .checkout-tab {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .checkout-stripe-placeholder {
    padding: 16px;
  }

  /* ============ Verify page ============ */
  .verify-card {
    padding: 22px 16px;
    border-radius: 20px;
  }

  .verify-card h1 {
    font-size: 1.2rem;
  }

  .verify-form input {
    padding: 12px 14px;
    font-size: 16px;
    letter-spacing: 0.3em;
  }

  /* ============ About page ============ */
  .about-hero h1 {
    font-size: 1.7rem;
  }

  .about-title {
    font-size: 1.5rem;
  }

  .about-section h2 {
    font-size: 1.6rem;
  }

  .about-hero-card {
    padding: 20px;
    border-radius: 20px;
  }

  .about-stat {
    padding: 16px;
    border-radius: 14px;
  }

  .about-world-card {
    grid-template-columns: 1fr;
    padding: 16px;
    border-radius: 18px;
  }

  .about-callout {
    padding: 20px;
    border-radius: 18px;
  }

  /* ============ Pricing page ============ */
  .pricing {
    padding: 24px 16px 56px;
  }

  .pricing-hero-copy h1 {
    font-size: 1.8rem;
  }

  .pricing-hero-panel {
    padding: 18px;
    border-radius: 14px;
  }

  .pricing-card {
    padding: 18px;
    border-radius: 14px;
  }

  .pricing-card h2 {
    font-size: 1.3rem;
  }

  .tier-credits-number {
    font-size: 2.2rem;
  }

  .pricing-cta-card {
    padding: 22px 16px;
    border-radius: 16px;
  }

  .pricing-compare table {
    min-width: 480px;
  }

  /* ============ Legal / TOS / Privacy ============ */
  .legal {
    padding: 22px 16px;
  }

  .legal h1 {
    font-size: 1.5rem;
  }

  .legal-page {
    padding: 16px;
    border-radius: 16px;
  }

  /* ============ Phiona portal ============ */
  .phiona-hero {
    padding: 18px;
    border-radius: 20px;
  }

  .phiona-section {
    padding: 14px;
    border-radius: 16px;
  }

  .phiona-value {
    font-size: 1.4rem;
  }

  .phiona-nav {
    padding: 14px;
    border-radius: 16px;
  }

  .phiona-step {
    padding: 12px;
    border-radius: 14px;
    gap: 12px;
  }

  .phiona-step-index {
    font-size: 1.3rem;
  }

  /* ============ Arcana page ============ */
  .arcana-hero-copy h1 {
    font-size: 1.7rem;
  }

  .arcana-hero-panel {
    padding: 18px;
    border-radius: 16px;
  }

  .arcana-story-card {
    padding: 16px;
    border-radius: 16px;
  }

  .arcana-card {
    padding: 16px;
    border-radius: 16px;
  }

  .arcana-team-header h2 {
    font-size: 1.5rem;
  }

  /* ============ Home page ============ */
  .feature-card {
    padding: 20px 16px;
    border-radius: 16px;
  }

  .cta-panel {
    padding: 24px 16px;
    border-radius: 18px;
  }
}
