/* ═══════════════════════════════════════════════════════════
   ARC-AGI Responsive Styles
   All responsive / media-query rules live here.
   Loaded AFTER common.css and testing_interface.css.

   PRINCIPLE: Grids must ALWAYS be visible. On small screens
   they stay side-by-side (input → output) inside a
   horizontally-scrollable container. Nothing is hidden.
   ═══════════════════════════════════════════════════════════ */

/* ── Base responsive fixes (all sizes) ────────────────────── */

body {
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

#modal_bg {
    padding: 16px;
    box-sizing: border-box;
}

#modal {
    max-width: 90vw;
    box-sizing: border-box;
}

#top_bar {
    box-sizing: border-box;
}

#workspace {
    max-width: 100%;
    box-sizing: border-box;
}

#examples_panel {
    min-width: 0;
    box-sizing: border-box;
}

#test_panel {
    min-width: 0;
    box-sizing: border-box;
}

#task_preview {
    box-sizing: border-box;
}

.pair_preview {
    box-sizing: border-box;
}

.pair_grids_row {
    min-width: 0;
}

.input_preview,
.output_preview {
    min-width: 0;
}

.control_row {
    box-sizing: border-box;
}

.control_group_left,
.control_group_right {
    flex-wrap: wrap;
}

#toolbar {
    flex-wrap: wrap;
}

#symbol_picker {
    flex-wrap: wrap;
}

.submit_row {
    flex-wrap: wrap;
}

#test_navigation {
    display: flex;
    flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════
   ≤ 1400px — Medium-large screens
   Give test panel slightly more room
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 1400px) {
    #examples_panel {
        flex: 0 0 48%;
        max-width: 48%;
    }
    #test_panel {
        flex: 0 0 52%;
        max-width: 52%;
        overflow: visible;
    }
    /* The container itself handles horizontal scroll — not the panel */
    #test_grids_container {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 10px 14px;
        max-width: 100%;
        box-sizing: border-box;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex-shrink: 1;
        min-width: 0;
        overflow: visible;
    }
    /* Labels must never be clipped — allow them to show fully */
    .grid_label {
        overflow: visible;
        white-space: nowrap;
        flex-shrink: 0;
    }
    #evaluation_input,
    #output_grid {
        overflow: visible;
        max-width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 1200px — Medium screens
   Shift more space to test panel, tighten arrows
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 1200px) {
    #examples_panel {
        flex: 0 0 45%;
        max-width: 45%;
    }
    #test_panel {
        flex: 0 0 55%;
        max-width: 55%;
        overflow: visible;
    }
    .pair_arrow {
        padding: 0 6px;
        font-size: 18px;
    }
    .arrow_separator {
        padding: 0 4px;
        font-size: 18px;
    }
    #top_bar {
        padding: 8px 16px;
    }
    /* The container itself handles horizontal scroll — not the panel */
    #test_grids_container {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 10px 14px;
        max-width: 100%;
        box-sizing: border-box;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex-shrink: 1;
        min-width: 0;
        overflow: visible;
    }
    .grid_label {
        overflow: visible;
        white-space: nowrap;
        flex-shrink: 0;
    }
    #evaluation_input,
    #output_grid {
        overflow: visible;
        max-width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 1000px — Tablet
   Stack PANELS vertically (examples on top, test below).
   Grids inside each pair stay side-by-side.
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 1000px) {
    #workspace {
        flex-direction: column;
    }
    #examples_panel,
    #test_panel {
        flex: none;
        max-width: 100%;
        width: 100%;
        overflow: visible;
    }
    #examples_panel {
        border-bottom: 1px solid #333;
    }
    #task_preview {
        padding-left: 10px;
        padding-right: 10px;
    }
    #test_grids_container {
        padding: 10px 10px;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        box-sizing: border-box;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex-shrink: 1;
        min-width: 0;
        overflow: visible;
    }
    .grid_label {
        overflow: visible;
        white-space: nowrap;
        flex-shrink: 0;
    }
    #evaluation_input,
    #output_grid {
        overflow: visible;
        max-width: 100%;
    }
    .pair_arrow {
        padding: 0 10px;
        font-size: 18px;
    }
    .arrow_separator {
        padding: 0 8px;
        font-size: 18px;
    }
    .control_row {
        flex-direction: column;
        align-items: flex-start;
    }
    .control_group_right {
        margin-top: 8px;
    }
    .section_header {
        padding: 12px 14px 8px 14px;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 768px — Small tablet / Large phone
   Test grids stack vertically.
   Example grids STAY side-by-side inside scrollable card.
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Top bar */
    #top_bar {
        padding: 8px 12px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
    }
    #top_bar_left {
        flex: 1 1 auto;
        min-width: 0;
    }
    #top_bar_right {
        flex: 0 0 auto;
    }
    .puzzle_id {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 60vw;
        display: inline-block;
    }

    /* Section headers — add scroll hint via ::after */
    .section_header {
        padding: 10px 12px 8px 12px;
        font-size: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .section_header::after {
        content: "SCROLL \2192";
        font-size: 9px;
        color: #666;
        letter-spacing: 0.5px;
        font-weight: 500;
        flex-shrink: 0;
    }

    /* Task preview / examples */
    #task_preview {
        padding: 6px 8px;
    }
    .pair_preview {
        padding: 8px;
        margin-bottom: 10px;
    }
    .pair_arrow {
        padding: 0 6px;
        font-size: 16px;
    }

    /* ── Test grids: stay SIDE-BY-SIDE (same as example grids) ──
       The row scrolls horizontally if grids overflow, just like
       .pair_grids_row does for examples. Nothing is stacked.    */
    #test_panel {
        overflow: visible;
    }
    #test_grids_container {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        height: auto !important;
        padding-bottom: 4px;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex: 0 0 auto;
        width: auto;
        min-width: 0;
        overflow: visible !important;
        height: auto !important;
    }
    .arrow_separator {
        transform: none;
        padding: 0 6px;
        align-self: center;
        font-size: 16px;
        flex-shrink: 0;
    }

    /* Evaluation and output grids — inline-block so they size
       to their cell content naturally within the scrollable row. */
    #evaluation_input {
        overflow: visible;
        display: inline-block;
    }
    #output_grid {
        overflow: visible;
        display: inline-block;
    }
    #output_grid .edition_grid {
        display: inline-block;
    }

    /* Tools & symbols */
    .tool_btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    .symbol_preview {
        width: 28px;
        height: 28px;
    }

    /* Step labels & controls */
    .step_label {
        font-size: 12px;
    }
    .control_section {
        padding: 8px 10px;
    }
    #test_navigation {
        gap: 8px;
        padding: 8px 10px;
    }
    .test_counter {
        font-size: 12px;
    }

    /* Labels */
    .pair_grid_label {
        font-size: 10px;
    }
    .grid_label {
        font-size: 10px;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 600px — Phone (larger phones like iPhone Plus/Max)
   Tighter spacing. Grids STAY side-by-side and scroll.
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 600px) {
    /* Modal */
    #modal {
        padding: 28px 20px 24px;
        border-radius: 12px;
        max-width: 95vw;
    }
    .modal_title {
        font-size: 18px;
    }
    .modal_subtitle {
        font-size: 12px;
        margin-bottom: 20px;
    }
    .modal_dropzone {
        padding: 20px 16px 18px;
    }
    .modal_browse_btn {
        padding: 8px 22px;
        font-size: 12px;
    }

    /* Top bar */
    #top_bar {
        padding: 6px 10px;
    }
    .puzzle_id {
        font-size: 11px;
        max-width: 55vw;
    }

    /* Examples */
    .pair_preview {
        padding: 6px;
        margin-bottom: 8px;
    }
    .pair_arrow {
        padding: 0 4px;
        font-size: 14px;
    }
    .arrow_separator {
        padding: 4px 0;
        font-size: 14px;
    }
    .pair_grid_label {
        font-size: 9px;
        margin-bottom: 4px;
    }
    .pair_grid_label .pair_grid_dims {
        font-size: 9px;
        margin-left: 4px;
    }
    .grid_label {
        font-size: 9px;
        margin-bottom: 4px;
    }
    .grid_dims {
        font-size: 9px;
        margin-left: 4px;
    }

    /* Buttons */
    .btn {
        font-size: 11px;
        padding: 5px 10px;
    }
    .btn code {
        font-size: 11px;
    }
    .grid_size_field {
        width: 50px;
        font-size: 12px;
        padding: 4px 6px;
    }

    /* Symbols & tools */
    .symbol_preview {
        width: 26px;
        height: 26px;
    }
    #symbol_picker {
        gap: 5px;
    }
    .tool_btn {
        padding: 5px 8px;
        font-size: 11px;
        gap: 3px;
    }
    .tool_icon {
        font-size: 12px;
    }
    #toolbar {
        gap: 4px;
        margin-bottom: 10px;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 480px — Phone (iPhone SE, standard phones)

   KEY DESIGN:
   - Example grids stay SIDE-BY-SIDE (input → output)
     inside a horizontally scrollable container.
   - NO vertical stacking of grid pairs.
   - NO dropdown / collapsed appearance.
   - Overflow is unlocked on entire ancestor chain so
     grids are ALWAYS visible and scrollable.
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    /* Modal */
    #modal {
        padding: 24px 16px 20px;
        width: 95vw;
        max-width: 95vw;
        border-radius: 10px;
    }
    .modal_icon svg {
        width: 40px;
        height: 40px;
    }
    .modal_title {
        font-size: 17px;
    }
    .modal_subtitle {
        font-size: 12px;
        margin-bottom: 16px;
    }
    .modal_dropzone {
        padding: 18px 12px 16px;
        border-radius: 8px;
    }
    .modal_dropzone_icon svg {
        width: 28px;
        height: 28px;
    }
    .modal_dropzone_text {
        font-size: 12px;
    }
    .modal_browse_btn {
        padding: 8px 20px;
        font-size: 12px;
        border-radius: 6px;
    }
    .modal_footer {
        font-size: 10px;
    }

    /* Top bar */
    #top_bar {
        padding: 6px 8px;
    }
    .puzzle_id {
        font-size: 10px;
        max-width: 50vw;
    }

    /* Section headers */
    .section_header {
        font-size: 11px;
        padding: 8px 8px 6px 8px;
        letter-spacing: 0.8px;
    }

    /* Task preview */
    #task_preview {
        padding: 4px 6px;
    }

    /* ──────────────────────────────────────────────────────
       CRITICAL: Unlock overflow on entire grid ancestor
       chain so grids are VISIBLE and can scroll.
       ────────────────────────────────────────────────────── */
    #workspace {
        overflow: visible;
    }
    #examples_panel {
        overflow: visible;
    }
    #test_panel {
        overflow: visible;
    }

    /* Pair cards — overflow visible so grids show */
    .pair_preview {
        padding: 4px;
        margin-bottom: 6px;
        overflow: visible;
    }

    /* ──────────────────────────────────────────────────────
       EXAMPLE GRIDS: Stay side-by-side (row), the entire
       pair_grids_row scrolls horizontally if needed.
       NO flex-direction: column. NO rotation of arrows.
       ────────────────────────────────────────────────────── */
    .pair_grids_row {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        align-items: flex-start;
        padding-bottom: 4px;
    }

    /* Input and output previews — do NOT collapse */
    .input_preview,
    .output_preview {
        flex: 0 0 auto;
        width: auto;
        min-width: 0;
        overflow: visible;
    }

    /* Grid containers — no clipping, auto width */
    .input_grid_container,
    .output_grid_container {
        overflow: visible;
        display: inline-block;
    }

    /* Grid display — let it be its natural size, no max-width clipping */
    .grid_display {
        max-width: none;
        overflow: visible;
    }

    /* Arrow stays as right-pointing arrow, not rotated */
    .pair_arrow {
        transform: none;
        padding: 0 6px;
        font-size: 16px;
        flex-shrink: 0;
        align-self: center;
    }

    .pair_grid_label {
        font-size: 9px;
        margin-bottom: 3px;
        white-space: nowrap;
    }
    .pair_grid_label .pair_grid_dims {
        font-size: 8px;
        margin-left: 3px;
    }

    /* ──────────────────────────────────────────────────────
       TEST GRIDS: Stay side-by-side (same as example grids).
       overflow is forced with !important to beat the base
       testing_interface.css overflow:hidden rules.
       ────────────────────────────────────────────────────── */
    #test_panel {
        overflow: visible !important;
    }

    /* ── TEST GRIDS: Stay SIDE-BY-SIDE (same as example grids) ──
       The entire #test_grids_container scrolls horizontally if
       grids overflow, matching the .pair_grids_row behavior.
       NO vertical stacking. NO rotation of arrows.               */
    #test_grids_container {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        height: auto !important;
        padding: 8px;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex: 0 0 auto;
        width: auto;
        min-width: 0;
        height: auto !important;
        overflow: visible !important;
    }

    /* Grid displays — inline-block so they size naturally.
       The parent row scrolls if they overflow. */
    #evaluation_input {
        overflow: visible;
        display: inline-block;
        max-width: none;
    }
    #output_grid {
        overflow: visible;
        display: inline-block;
        max-width: none;
    }
    #output_grid .edition_grid {
        display: inline-block;
        overflow: visible;
    }

    /* Arrow stays horizontal — right-pointing, not rotated */
    .arrow_separator {
        transform: none;
        padding: 0 6px;
        align-self: center;
        font-size: 14px;
        flex-shrink: 0;
    }
    .grid_label {
        font-size: 9px;
        margin-bottom: 3px;
    }
    .grid_dims {
        font-size: 8px;
    }

    /* Controls */
    .step_label {
        font-size: 11px;
        margin-bottom: 8px;
    }
    .control_section {
        padding: 6px 8px;
        margin-top: 1%;
    }
    .control_row {
        gap: 6px;
    }
    .control_group_left {
        gap: 4px;
    }
    .control_group_right {
        gap: 4px;
        margin-top: 4px;
    }
    .btn {
        font-size: 10px;
        padding: 5px 8px;
    }
    .btn code {
        font-size: 10px;
    }
    .btn-submit {
        padding: 6px 14px;
    }
    .grid_size_field {
        width: 46px;
        font-size: 11px;
        padding: 4px 4px;
    }
    .tool_btn {
        padding: 5px 7px;
        font-size: 10px;
    }
    .tool_icon {
        font-size: 11px;
    }
    .symbol_preview {
        width: 24px;
        height: 24px;
        border-radius: 3px;
        margin-right: 2px;
    }
    #symbol_picker {
        gap: 4px;
    }
    #toolbar {
        gap: 3px;
        margin-bottom: 8px;
    }
    #test_navigation {
        gap: 6px;
        padding: 6px 8px;
    }
    .test_counter {
        font-size: 11px;
    }
    .submit_row {
        gap: 4px;
    }
    #error_display,
    #info_display {
        font-size: 11px;
        margin-left: 4px;
    }

    /* ── Scroll hint: subtle scrollbar for grid containers ── */
    .pair_grids_row::-webkit-scrollbar,
    #test_grids_container::-webkit-scrollbar {
        height: 4px;
    }
    .pair_grids_row::-webkit-scrollbar-track,
    #test_grids_container::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 2px;
    }
    .pair_grids_row::-webkit-scrollbar-thumb,
    #test_grids_container::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
        border-radius: 2px;
    }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 380px — Very small phone (iPhone SE 1st gen, etc)
   Even more compact. Grids still side-by-side + scrollable.
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 380px) {
    #modal_bg {
        padding: 8px;
    }
    #modal {
        padding: 20px 12px 16px;
        border-radius: 8px;
        max-width: 98vw;
    }
    .modal_icon svg {
        width: 36px;
        height: 36px;
    }
    .modal_title {
        font-size: 16px;
    }
    .modal_subtitle {
        font-size: 11px;
        margin-bottom: 14px;
    }
    .modal_dropzone {
        padding: 14px 10px 12px;
    }
    .modal_dropzone_text {
        font-size: 11px;
    }
    .modal_browse_btn {
        padding: 7px 18px;
        font-size: 11px;
    }

    #top_bar {
        padding: 5px 6px;
    }
    .puzzle_id {
        font-size: 9px;
        max-width: 45vw;
    }
    .section_header {
        font-size: 10px;
        padding: 6px 6px 4px 6px;
    }
    .pair_preview {
        padding: 3px;
        margin-bottom: 5px;
        overflow: visible;
    }
    .pair_grid_label {
        font-size: 8px;
        margin-bottom: 2px;
    }
    .pair_grid_label .pair_grid_dims {
        font-size: 7px;
    }
    .pair_arrow {
        padding: 0 4px;
        font-size: 14px;
    }
    .step_label {
        font-size: 10px;
        margin-bottom: 6px;
    }
    .control_section {
        padding: 5px 6px;
    }
    .btn {
        font-size: 9px;
        padding: 4px 6px;
    }
    .btn code {
        font-size: 9px;
    }
    .grid_size_field {
        width: 42px;
        font-size: 10px;
    }
    .tool_btn {
        padding: 4px 6px;
        font-size: 9px;
    }
    .symbol_preview {
        width: 22px;
        height: 22px;
        margin-right: 1px;
        border-radius: 2px;
    }
    #symbol_picker {
        gap: 3px;
    }
    #test_navigation {
        padding: 5px 6px;
        gap: 4px;
    }
    .test_counter {
        font-size: 10px;
    }
    .grid_label {
        font-size: 8px;
    }
    .grid_dims {
        font-size: 7px;
    }
}

/* ═══════════════════════════════════════════════════════════
   Landscape phones (short + wide)
   Keep side-by-side layout, shrink modal
   ═══════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    #modal {
        padding: 16px 20px 12px;
        max-height: 90vh;
        max-height: 90dvh;
        overflow-y: auto;
    }
    .modal_icon {
        margin-bottom: 8px;
    }
    .modal_icon svg {
        width: 32px;
        height: 32px;
    }
    .modal_title {
        font-size: 16px;
        margin-bottom: 4px;
    }
    .modal_subtitle {
        font-size: 11px;
        margin-bottom: 12px;
    }
    .modal_dropzone {
        padding: 12px 14px 10px;
    }

    /* Force side-by-side in landscape even on small screens */
    #workspace {
        flex-direction: row;
    }
    #examples_panel {
        flex: 0 0 48%;
        max-width: 48%;
        border-bottom: none;
    }
    #test_panel {
        flex: 0 0 52%;
        max-width: 52%;
    }

    /* Keep pair grids side-by-side */
    .pair_grids_row {
        flex-direction: row;
    }
    .pair_arrow {
        transform: none;
        padding: 0 4px;
    }

    /* Keep test grids side-by-side (same as example grids) */
    #test_grids_container {
        flex-direction: row;
        flex-wrap: nowrap;
        height: auto !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
    }
    .arrow_separator {
        transform: none;
        padding: 0 4px;
        flex-shrink: 0;
    }
    #test_input_wrapper,
    #test_output_wrapper {
        flex: 0 0 auto;
        width: auto;
        overflow: visible;
        -webkit-overflow-scrolling: touch;
    }
}

/* ═══════════════════════════════════════════════════════════
   Touch device enhancements
   Minimum tap target sizes for usability
   ═══════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    .cell {
        min-width: 8px;
        min-height: 8px;
    }
    .tool_btn {
        min-height: 36px;
    }
    .btn {
        min-height: 34px;
    }
    .symbol_preview {
        min-width: 28px;
        min-height: 28px;
    }
    .modal_browse_btn {
        min-height: 42px;
    }
}
