body.tables-show {
  /* Fallback for older browsers */
  max-height: 100vh;
  /* Use dynamic viewport height on modern mobile browsers */
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.tables-new #setting-details {
  padding: 1rem;
}

body.tables-new .setting-details-content {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

body.tables-new .setting-details-media {
  flex: 0 0 11rem;
  max-width: 11rem;
}

body.tables-new .setting-details-image {
  width: 100%;
  min-height: 12rem;
  border-radius: var(--form-radius);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

body.tables-new .setting-details-copy {
  min-width: 0;
  flex: 1 1 auto;
}

body.tables-new .setting-details-prompt {
  white-space: pre-wrap;
}

body.tables-show footer {
  display: none;
}

#TableShow {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  /* Fallback first, then dvh for mobile URL bar handling */
  max-height: calc(100vh - 45px);
  max-height: calc(100dvh - 45px);
  padding-bottom: 200px;
}

#TableShow nav.button-group.is-tabs {
  padding: 0;
  width: 100%;
}

#TableShow .channel-content {
  /* Fallback first, then dvh for mobile URL bar handling */
  min-height: calc(100vh - 100px);
  min-height: calc(100dvh - 100px);
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
}

#TableShow nav.button-group .button:first-child {
  border-bottom-left-radius: 0;
}

#TableShow nav.button-group .button:last-child {
  border-bottom-right-radius: 0;
}

#TableShow nav.button-group .button.is-selected {
  border-bottom: 2px solid black;
}

#TableShow {
  --table-character-accent: var(--color-character-accent);
  --table-character-accent-rgb: var(--color-character-accent-rgb);
}

#TableShow nav.button-group .button.character-tab {
  color: var(--table-character-accent);
}

#TableShow nav.button-group .button.character-tab.is-selected {
  border-bottom-color: var(--table-character-accent);
  box-shadow: inset 0 -2px 0 var(--table-character-accent);
}

/* Story tab specific styling for seamless look */
/* Remove padding and background from story tab-container so inner elements create the seamless unit */
#TableShow section.tab-container:has(.story-log) {
  padding: 0;
  background-color: transparent;
  border: none;
}

/* Story log forms the top of the seamless unit */
#TableShow .story-log {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-top: 0;
  margin-bottom: 0;
  border-bottom: none;
  border-top: none;
}

/* Remove border radius from elements that should be seamlessly connected */
#TableShow .table-characters-badge-list {
  margin-top: 0;
  margin-bottom: 0;
}

#TableShow #audio-player {
  margin-top: 0;
  margin-bottom: 0;
}

#TableShow .table-audio-disabled-notice {
  background-color: rgba(0, 0, 0, 0.04);
  color: rgba(0, 0, 0, 0.75);
}

/* Remove all border radius from textarea to connect story log and submit button */
#TableShow .input-submission-container textarea {
  border-radius: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.2);
  border-bottom: none;
}

/* Remove margin and border radius from input container to connect to story log */
#TableShow .input-submission-container {
  margin-top: 0;
  margin-bottom: 0;
  border-radius: 0;
}

/* Status panes (scene being written, submitting, retry, etc.) replace the
   input form and must close the seamless unit at the bottom the same way the
   input does: a top divider, side + bottom borders, and matching bottom radius
   so they attach flush to the story log instead of floating borderless. */
#TableShow .story-status-pane {
  margin: 0;
  padding: var(--base-spacing) calc(var(--base-spacing) * 2);
  background-color: var(--color-box);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-top: 1px solid rgba(0, 0, 0, 0.2);
  border-bottom-left-radius: var(--form-radius);
  border-bottom-right-radius: var(--form-radius);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  /* Occupy the same footprint the input form would and center the status
     text within it, so the story log doesn't jump and the message sits
     vertically centered. */
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 130px;
}

#TableShow .story-status-pane p:last-child {
  margin-bottom: 0;
}

/* Submit button closes the seamless unit at the bottom */
#TableShow .action-submit {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
}

#TableShow .table-errors {
  right: var(--base-spacing);
  top: var(--base-spacing);
  position: absolute;
  z-index: 5;
  max-width: 90vw;
}

#TableShow .tab-container {
  /* Fallback first, then dvh for mobile URL bar handling */
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  display: flex;
  flex-direction: column;
  /* Tab containers should have borders and connect seamlessly with button group */
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-bottom-left-radius: var(--form-radius);
  border-bottom-right-radius: var(--form-radius);
  background-color: var(--color-box);
  padding: var(--base-spacing);
}

@media (max-height: 768px) {
  #TableShow .table-characters-badge-list {
    display: none;
  }
}

/* Mobile-specific styles */
@media (max-width: 768px) {
  body.tables-new .setting-details-content {
    flex-direction: column;
  }

  body.tables-new .setting-details-media {
    flex-basis: auto;
    max-width: 100%;
    width: 100%;
  }

  body.tables-new .setting-details-image {
    min-height: 9rem;
  }

  body.tables-show {
    #TableShow {
      font-size: 1.05rem;
      width: 100%;
      max-width: 100%;
      margin: 0;
      padding: 0;
    }

    /* Remove box styling from tab containers on mobile */
    #TableShow .tab-container {
      padding: 0.5rem;
      margin: 0;
      border: none;
      box-shadow: none;
      background: transparent;
      max-height: none !important;
      height: auto !important;
      flex-grow: 1;
    }

    /* Switch to window scrolling on mobile - apply to body.tables-show directly */
      overflow: visible !important;
      max-height: none !important;
      height: auto !important;

    #TableShow {
      max-height: none !important;
      height: auto !important;
      padding-bottom: 0 !important;
    }

    #TableShow .channel-content {
      min-height: 100dvh;
      height: auto !important;
      max-height: none !important;
      overflow: visible !important;
      padding-bottom: 0;
    }

    /* Disable internal scroll for story log */
    #TableShow .tab-container .story-log {
      overflow: visible !important;
      max-height: none !important;
    }

    /* Sticky Header */
    #TableShow nav.button-group.is-tabs {
      position: sticky;
      top: 0;
      z-index: 100;
      background-color: #fff;
      padding: 4px 6px;
      width: 100%;
    }

    /* Sticky Input */
    #TableShow .input-submission-container {
      position: sticky;
      bottom: 0;
      z-index: 100;
      background-color: #fff; /* not transparent w/ sticky */
      padding: 10px;
      margin-bottom: 0;
      border-top: 1px solid rgba(0,0,0,0.1);
    }

    #TableShow nav.button-group.is-tabs .button {
      border-radius: 0;
    }

    /* On mobile the story content is borderless, so the status pane keeps just
       the top divider to stay consistent with the sticky input treatment. */
    #TableShow .story-status-pane {
      border-left: none;
      border-right: none;
      border-bottom: none;
      border-radius: 0;
      background-color: transparent;
      padding: 10px;
      min-height: 0;
    }

    /* Minimal padding for text content - remove box styling */
    #TableShow .tab-container article.box,
    #TableShow .tab-container .box {
      padding: 0.5rem;
      margin-left: 0;
      margin-right: 0;
      border: none;
      box-shadow: none;
      background-color: transparent;
      border-radius: 0;
    }

    /* Remove bottom spacing under input for full height */
    #TableShow .tab-container article:last-child {
      margin-bottom: 0;
    }

    /* Full height input section */
    #TableShow article.w-100.flex-shrink-0 {
      margin-bottom: 0;
      padding-bottom: 0;
    }

    #TableShow article.w-100.flex-shrink-0 button {
      margin-bottom: 0;
    }

    /* Error box adjustments */
    #TableShow nav.table-errors {
      margin: 0;
      border-radius: 0;
    }

    /* Audio player padding reduction */
    #TableShow #audio-player {
      padding-left: 0.5rem;
      padding-right: 0.5rem;
    }

    /* Table character badges */
    #TableShow .table-characters-badge-list {
      padding-left: 0.5rem;
      margin-top: 0.5rem;
    }

    /* Force advance button */
    #TableShow button.is-link.mb3 {
      margin-bottom: 0;
    }
  }
}

/* Quick Start Character Introduction Panel */
@keyframes quick-start-slide-up {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.quick-start-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  border-radius: 16px 16px 0 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
  padding: 1rem 1rem 1.25rem;
  animation: quick-start-slide-up 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 60vh;
  overflow-y: auto;
}

.quick-start-character-panel {
  border-top: 3px solid var(--table-character-accent);
  box-shadow: 0 -4px 28px rgba(var(--table-character-accent-rgb), 0.38), 0 0 0 1px rgba(var(--table-character-accent-rgb), 0.16);
}

.quick-start-character-panel .badge-circle {
  background-color: var(--table-character-accent);
  box-shadow: 0 0 0 4px rgba(var(--table-character-accent-rgb), 0.18);
}

.quick-start-panel-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.2);
  margin: 0 auto 1rem;
}

.quick-start-panel-label {
  font-size: 0.7rem;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.quick-start-panel-hint {
  font-size: 0.75rem;
  opacity: 0.5;
  text-align: center;
  margin: 0;
}

/* Entry/leave transitions */
.quick-start-enter-active {
  animation: quick-start-slide-up 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.quick-start-leave-active {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.quick-start-leave-to {
  opacity: 0;
  transform: translateY(16px);
}

/* Desktop: centered panel */
@media (min-width: 769px) {
  .quick-start-panel {
    left: calc(50% - 240px);
    right: auto;
    width: 480px;
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-color-scheme: dark) {
  .quick-start-panel-handle {
    background: rgba(255, 255, 255, 0.2);
  }
}

/* Character counter for submission textarea */
.submission-char-counter {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.75rem;
  background-color: rgba(255, 255, 255, 0.9);
  color: rgba(0, 0, 0, 0.6);
  border-radius: 0.25rem;
  padding: 0.15rem 0.25rem;
  line-height: 1;
  font-family: sans-serif;
  pointer-events: none;
  opacity: 0.8;
}

.submission-char-counter.is-invalid {
  color: #ff4136;
  font-weight: bold;
}

@media (prefers-color-scheme: dark) {
  #TableShow .tab-container {
    border-color: rgba(255, 255, 255, 0.15);
  }

  #TableShow .table-audio-disabled-notice {
    background-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
  }

  .submission-char-counter {
    background-color: rgba(0, 0, 0, 0.8);
    color: rgba(255, 255, 255, 0.7);
  }

  .submission-char-counter.is-invalid {
    color: #ff6b6b;
  }

  @media (max-width: 768px) {
    body.tables-show {
      #TableShow nav.button-group.is-tabs {
        background-color: #333;
      }

      #TableShow .input-submission-container {
        background-color: #333;
        border-top: 1px solid #555;
      }
    }
  }
}
