/* Mobile app-shell styles layered on top of index.css (the original engine sprite styles). */

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    margin: 0;
    padding: 0;
    /* iOS standalone PWAs under-measure height (100%/100vh/100dvh) by the
       safe-area insets, leaving slivers of the body's own background
       exposed above/below the app content. Pinning body to the viewport
       edges sidesteps height-unit quirks entirely and guarantees it
       always spans the true visible screen, safe areas included. */
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background-color: #c0c0c0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    touch-action: manipulation;
}

body.night-mode {
    background-color: #000;
}

/* ---------- Board viewport (auto-scales the classic board to fit the screen) ---------- */

#board-viewport {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    min-height: 0;
}

#board-scale-box {
    position: relative;
}

#board-scale-box #game-container {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    margin-right: 0;
}

#board-scale-box #game-container * {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* ---------- Selection overlay ---------- */

#tile-selector {
    position: absolute;
    display: none;
    box-sizing: border-box;
    border: 3px solid #2196f3;
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.35), 0 0 10px rgba(33, 150, 243, 0.9);
    pointer-events: none;
    z-index: 500;
    animation: tile-selector-pulse 1.3s ease-in-out infinite;
}

@keyframes tile-selector-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---------- Directional pad (manual selection movement) ---------- */

#dpad {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 6px;
    justify-content: center;
    align-content: center;
    padding: 8px 0;
    background-color: #2b2f38;
}

body.night-mode #dpad {
    background-color: #05070a;
}

#dpad-up { grid-column: 2; grid-row: 1; }
#dpad-left { grid-column: 1; grid-row: 2; }
#dpad-down { grid-column: 2; grid-row: 2; }
#dpad-right { grid-column: 3; grid-row: 2; }

.dpad-btn {
    border: none;
    border-radius: 10px;
    background-color: #3d4452;
    color: #f2f2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.08s ease, background-color 0.15s ease;
}

.dpad-btn:active {
    transform: scale(0.9);
    background-color: #4c5566;
}

.dpad-btn:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

.dpad-icon {
    width: 24px;
    height: 24px;
    display: block;
    pointer-events: none;
}

/* ---------- Bottom action bar ---------- */

#bottom-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 10px calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px));
    background-color: #2b2f38;
}

body.night-mode #bottom-bar {
    background-color: #05070a;
}

#bottom-bar button {
    border: none;
    border-radius: 10px;
    background-color: #3d4452;
    color: #f2f2f2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-family: inherit;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.08s ease, background-color 0.15s ease;
}

#bottom-bar button:active {
    transform: scale(0.94);
    background-color: #4c5566;
}

#bottom-bar button:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

.action-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 4px;
    font-size: 13px;
    font-weight: bold;
}

.action-icon {
    width: 30px;
    height: 30px;
    display: block;
    pointer-events: none;
}

img.action-icon {
    width: 24px;
    height: auto;
    object-fit: contain;
}

.action-label {
    pointer-events: none;
}

#gear-btn {
    flex: 0 0 52px;
    padding: 6px;
}

#gear-btn .action-icon {
    width: 26px;
    height: 26px;
}

/* Shown in place of Flag/Skip/Open once the game is over; naturally fills
   the same combined width since the other three are hidden (display:none),
   not just visually collapsed, so their flex space is freed up entirely.
   min-height keeps the bar's height from shrinking once it's the only
   button left standing next to the (shorter) gear button - without this,
   #bottom-bar's align-items:stretch would size the row to whichever
   visible button is naturally shortest. */
.new-game-btn {
    background-color: #06f;
    min-height: 70px;
    font-size: 16px;
}

.new-game-btn:active {
    background-color: #1a7aff;
}

body.night-mode .new-game-btn {
    background-color: #184292;
}

/* ---------- Modal (options) ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
}

.modal-overlay.open {
    display: block;
}

.modal {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(360px, 92vw);
    max-height: 86vh;
    overflow-y: auto;
    background: #f2f2f2;
    border-radius: 12px;
    z-index: 901;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    font-family: arial, sans-serif;
}

.modal.open {
    display: block;
}

body.night-mode .modal {
    background: #2a2a2a;
    color: #ddd;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #06f;
    color: #fff;
    border-radius: 12px 12px 0 0;
    position: sticky;
    top: 0;
}

body.night-mode .modal-header {
    background: #184292;
}

.modal-header h2 {
    margin: 0;
    font-size: 17px;
}

.modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
}

.modal-body {
    padding: 14px 16px 20px;
}

.option-group {
    border: 1px solid #ccc;
    border-radius: 8px;
    margin: 0 0 16px;
    padding: 10px 12px 14px;
}

body.night-mode .option-group {
    border-color: #555;
}

.option-group legend {
    font-weight: bold;
    padding: 0 6px;
}

.radio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
    font-size: 15px;
    cursor: pointer;
}

.radio-row input {
    width: 18px;
    height: 18px;
    margin: 0;
}

.dim-hint {
    margin-left: auto;
    color: #777;
    font-size: 12px;
}

body.night-mode .dim-hint {
    color: #aaa;
}

.custom-fields {
    display: none;
    gap: 8px;
    padding: 6px 4px 2px 30px;
}

.custom-fields.visible {
    display: flex;
}

.custom-fields label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    gap: 3px;
    flex: 1;
}

.custom-fields input {
    font-size: 15px;
    padding: 6px;
    width: 100%;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    font-size: 15px;
    cursor: pointer;
}

.switch-row input {
    width: 20px;
    height: 20px;
}

.primary-btn {
    width: 100%;
    margin-top: 10px;
    padding: 12px;
    font-size: 15px;
    font-weight: bold;
    background: #06f;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.secondary-btn {
    flex: 1;
    padding: 10px;
    font-size: 14px;
    background: #ddd;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

body.night-mode .secondary-btn {
    background: #444;
    color: #eee;
}

.import-export-row {
    display: flex;
    gap: 8px;
}

#export-textarea,
#import-textarea {
    width: 100%;
    height: 60px;
    margin-top: 10px;
    font-family: monospace;
    font-size: 12px;
    padding: 6px;
    resize: vertical;
}

#export-first-click-message {
    margin-top: 8px;
    font-size: 12px;
    color: #555;
}

body.night-mode #export-first-click-message {
    color: #bbb;
}

.option-hint {
    margin: 0 0 10px;
    font-size: 12px;
    color: #555;
}

body.night-mode .option-hint {
    color: #bbb;
}

#import-submit-btn {
    margin-top: 8px;
}

/* ---------- Share dialog (repositioned as a centered modal) ---------- */

#share {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    width: min(480px, 92vw) !important;
    max-width: 92vw;
    z-index: 902;
    background: #f2f2f2;
    border-radius: 10px;
    padding: 16px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    margin-top: 0 !important;
}

body.night-mode #share {
    background: #2a2a2a;
    color: #ddd;
}

#share-blurb {
    max-width: 100%;
    overflow-wrap: break-word;
}

#share-close-quote {
    left: auto !important;
    right: -12px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
