/* ── Gigataba Mobile Responsive Stylesheet ─────────────────────────────────
   Included after the theme stylesheet. Targets screens up to 768px wide.
   ─────────────────────────────────────────────────────────────────────────── */

/* ── Base: prevent horizontal overflow ──────────────────────────────────── */
html, body {
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}
*, *::before, *::after {
  box-sizing: inherit;
}

/* ── Make images/media never overflow their container ───────────────────── */
img, video, audio, canvas {
  max-width: 100%;
  height: auto;
}

@media (max-width: 768px) {

  /* ── Body ──────────────────────────────────────────────────────────────── */
  body {
    font-size: 14px;
    padding: 0 4px;
  }

  /* ── Top navigation bar ────────────────────────────────────────────────── */
  .topbar {
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 2px;
    font-size: 12px;
  }
  .menubar {
    font-size: 12px;
    flex: 1 1 100%;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    width: 100%;
    text-align: center;
  }
  .adminbar {
    font-size: 12px;
    flex-shrink: 1;
    white-space: normal;
    text-align: center;
    word-break: break-word;
    float: right;
    width: 100%;
  }

  /* ── Board banner: always 300x100 ─────────────────────────────────────── */
  .logo {
    font-size: 18pt;
  }

  /* ── Post form: replace <table> layout with stacked flex ───────────────── */
  .postarea form > table,
  .postarea form > table tbody {
    display: block;
    width: 100%;
  }
  .postarea form > table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: 6px;
    gap: 4px;
  }
  .postarea form > table tr > td {
    display: block;
  }
  .postarea form > table tr > td.postblock {
    min-width: 80px;
    max-width: 90px;
    flex-shrink: 0;
    font-size: 12px;
    padding: 4px 6px;
  }
  .postarea form > table tr > td:not(.postblock) {
    flex: 1 1 0;
    min-width: 0;
  }

  /* ── Form inputs: full width on mobile ─────────────────────────────────── */
  .postarea input[type="text"],
  .postarea input[type="password"],
  .postarea input[type="email"],
  .postarea textarea {
    width: 100% !important;
    max-width: 100% !important;
    font-size: 16px; /* prevents iOS zoom-on-focus */
    box-sizing: border-box;
  }
  /* The subject+submit row: stack them */
  .postarea form > table tr > td:not(.postblock) > input[type="submit"] {
    display: block;
    margin-top: 4px;
    padding: 6px 16px;
    font-size: 14px;
  }

  /* ── Drop zone / file upload area ──────────────────────────────────────── */
  #drop-zone {
    min-width: unset !important;
    width: 100%;
    padding: 12px 8px;
  }
  #file-slots {
    gap: 4px;
  }

  /* ── Oekaki canvas: shrink to fit ──────────────────────────────────────── */
  #tegaki-canvas {
    max-width: 100%;
    width: 100% !important;
    height: auto !important;
    touch-action: none;
  }
  #tegaki-preview-img {
    max-width: 100% !important;
  }

  /* ── Attach tabs: scale down ───────────────────────────────────────────── */
  #attach-tabs {
    flex-wrap: wrap;
  }
  #attach-tabs button {
    font-size: 12px;
    padding: 4px 10px;
  }

  /* ── Reply posts: unwrap the <table><tr><td> layout ────────────────────── */
  .post-body > table,
  .post-wrap > table {
    display: block;
    width: 100%;
    margin-left: 0 !important;
  }
  .post-body > table tr,
  .post-body > table tbody,
  .post-wrap > table tr,
  .post-wrap > table tbody {
    display: block;
    width: 100%;
  }
  td.reply {
    display: block;
    width: 100%;
    padding: 4px 6px;
  }

  /* ── Thumbnails: don't let them be too wide ────────────────────────────── */
  a img[id$="-thumb"] {
    max-width: 120px;
    height: auto;
  }
  .multi-file-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .multi-file-item {
    max-width: 48%;
  }

  /* ── Settings panel: full-width on narrow screens ──────────────────────── */
  #settings-panel {
    width: 90vw !important;
    max-width: 360px;
    min-width: unset !important;
    padding: 14px 14px 12px;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* ── Admin dialog ──────────────────────────────────────────────────────── */
  #admin-dialog {
    width: 90vw !important;
    min-width: unset !important;
    padding: 14px 14px;
  }

  /* ── Pagination table: make it flex ────────────────────────────────────── */
  #board-content > form > table[align="right"],
  #board-content > table {
    width: 100% !important;
    display: block;
  }
  #board-content > table tr,
  #board-content > table tbody {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
  }
  #board-content > table td {
    display: block;
  }

  /* ── Delete form row (align="right" table) ──────────────────────────────── */
  table[align="right"] {
    display: block;
    width: 100%;
    text-align: center;
    float: none !important;
    clear: both;
    margin: 6px 0;
  }
  table[align="right"] tr,
  table[align="right"] tbody {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }
  table[align="right"] td {
    display: block;
    text-align: center;
  }

  /* ── Ref preview: constrain on narrow screens ──────────────────────────── */
  #ref-preview {
    max-width: 90vw !important;
  }

  /* ── Post header: allow wrapping ───────────────────────────────────────── */
  .post-wrap {
    overflow-wrap: break-word;
    word-break: break-word;
  }
  .post-wrap > .filetitle,
  .post-wrap > .postername,
  .post-wrap > .commentpostername {
    font-size: 14px;
  }

  /* ── Blockquotes: tighter indent on mobile ──────────────────────────────── */
  .post-body blockquote {
    margin-left: 2px;
  }



  /* ── Delete password row ────────────────────────────────────────────────── */
  tr > td > input[name="pwd"] {
    width: 80px;
  }

  /* ── HR separator ───────────────────────────────────────────────────────── */
  hr {
    margin: 6px 0;
  }

  /* ── Stack attachments above text on mobile ─────────────────────────────── */
  /* Clear inline float:left set by board.py on image/video/audio anchors */
  .post-body a[style*="float"],
  .post-body > a[id$="-anchor"],
  .post-body > video[style*="float"],
  .post-body .spoiler-wrap[style*="float"] {
    float: none !important;
    display: block !important;
    margin-right: 0 !important;
    margin-bottom: 6px !important;
  }
  /* Make post-reply-content (text + replies) sit below instead of beside */
  .post-reply-content {
    display: block;
    overflow: visible;
    clear: both;
    width: 100%;
  }
  /* Multi-file grid: stack items full-width */
  .multi-file-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .multi-file-item {
    max-width: 100% !important;
    align-items: flex-start !important;
  }
}

/* ── Very small phones (< 400px) ──────────────────────────────────────────── */
@media (max-width: 400px) {
  body {
    font-size: 13px;
    padding: 0 2px;
  }
  .postarea form > table tr > td.postblock {
    min-width: 68px;
    max-width: 72px;
    font-size: 11px;
  }
  .logo {
    font-size: 15pt;
  }
  .board-banner-text {
    font-size: 13pt;
  }
  a img[id$="-thumb"] {
    max-width: 90px;
  }
  .multi-file-item {
    max-width: 100%;
  }
}
