/* ==========================================================================
   Grid Puzzle Game – Custom CSS Stylesheet
   --------------------------------------------------------------------------
   Description:
   This stylesheet defines custom styles for the mobile UI,
   including grid layout, canvas overlay, region borders, mobile responsiveness,
   action bars, and visual themes (e.g., black & white mode, error indicators).

   Features Covered:
   - Responsive grid layout with adjustable aspect ratio
   - Region-specific borders for grid segmentation
   - SVG icon styling for grid marks (star, dot, X)
   - Top and bottom toolbar styles with interactive feedback
   - Contextual tools, modals, and toggle switches
   - Button styles with animation and accessibility support
   - Black & white theme and error state visuals

   Author: Isaiah Tadrous
   Last Updated: [2025-09-08]
========================================================================== */


#grid-and-canvas-container {
    position: relative;
    width: 100%;
    height: auto;
    max-width: 95vmin; /* Use vmin to keep it square and fitting on screen */
    max-height: 95vmin;
    aspect-ratio: 1 / 1;
}

.grid-container {
    display: grid;
    border: 3px solid #1f2937; /* A dark gray border */
    touch-action: none;
    width: 100%;
    height: 100%;
}

.grid-cell {
    position: relative;
    border-right: 1px solid #84878c; /* gray vertical line */
    border-bottom: 1px solid #84878c; /* gray horizontal line */
    user-select: none; /* Prevent selecting the SVG icons */
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-cell:nth-child(var(--grid-dim)n) { border-right: none; }
.grid-cell:nth-last-child(-n+var(--grid-dim)) { border-bottom: none; }
.region-border-t { border-top: 2px solid #1f2937; }
.region-border-b { border-bottom: 2px solid #1f2937; }
.region-border-l { border-left: 2px solid #1f2937; }
.region-border-r { border-right: 2px solid #1f2937; }
.star-svg { color: #f59e0b; filter: drop-shadow(0px 1px 1px rgb(0 0 0 / 0.8)); }
.dot-svg { color: #4b5563; }
.x-svg { color: #374151; }

.grid-cell svg { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    animation: popIn 0.2s ease-out;
}

#draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- MOBILE LAYOUT STYLES --- */

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    position: fixed;
    width: 100%;
}
#game-screen {
    height: 100vh;
    height: -webkit-fill-available;
}
#grid-wrapper {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 8px;
}

/* --- TOP BAR STYLES -- */
.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem; /* 4px */
}
.top-bar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background-color: transparent;
    border-radius: 9999px;
    color: #d1d5db;
    padding: 0;
}
.top-bar-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}
.top-bar-btn:disabled {
    color: #6b7280 !important;
    background-color: transparent !important;
    opacity: 0.5;
    cursor: not-allowed;
}


/* --- BOTTOM TOOLBAR STYLING --- */
#bottom-toolbar {
    flex-shrink: 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}

/* NEW: Styles for the action bar */
#action-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.action-bar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background-color: transparent;
    border-radius: 9999px;
    color: #d1d5db;
    padding: 0;
}
.action-bar-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
.action-bar-btn.red-icon { color: #fca5a5; }
.action-bar-btn.green-icon { color: #86efac; }
.action-bar-btn.red-icon:hover { color: #f87171; }
.action-bar-btn.green-icon:hover { color: #4ade80; }
.action-bar-btn:disabled {
    color: #6b7280 !important;
    background-color: transparent !important;
    opacity: 0.5;
    cursor: not-allowed;
}


#mode-tools-tab {
    display: flex !important;
    flex-direction: row;
    gap: 0.5rem;
}

.contextual-box {
    background-color: rgba(0,0,0,0.2);
    border-radius: 0.5rem;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
#contextual-controls, #toggle-mark-btn {
    margin-top: 0 !important;
}


/* --- HAMBURGER MENU STYLES --- */
#puzzle-actions-tab {
    position: absolute;
    bottom: 100%; 
    right: 0.5rem; 
    margin-bottom: 0.5rem; 
    background-color: #2d3748; 
    border-radius: 0.5rem;
    padding: 0.5rem;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.5);
    z-index: 20;
    display: none;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    width: 150px;
}
#puzzle-actions-tab.is-open {
    display: grid;
}

/* --- UPDATED "CLICKY" BUTTON STYLES --- */
.toolbar-btn, .top-bar-btn, .color-slot, .action-bar-btn {
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
    cursor: pointer;
}
.toolbar-btn:active, .top-bar-btn:active, .color-slot:active, .action-bar-btn:active,
.toolbar-btn.btn-active, .top-bar-btn.btn-active, .color-slot.btn-active, .action-bar-btn.btn-active {
    transform: scale(0.92);
    filter: brightness(0.85);
    transition: transform 0.05s ease-out;
}

/* --- Other Button Styles --- */
.toolbar-btn {
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 0.5rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.25);
	padding: 0.25rem 1rem; /* <-- Add this line */
}
.mode-btn {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1/1;
}

.mode-btn.selected {
    background-color: #1d232b !important;
    color: #c1c4c9;
    outline: 2px solid #4f46e5;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
button:disabled, .toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #4b5563 !important;
    transform: none !important;
    filter: none !important;
    box-shadow: none !important;
}

/* --- MISC STYLES --- */
.color-slot {
    width: 100%;
    height: 2.25rem;
    border-radius: 0.375rem;
    cursor: pointer;
    border: 2px solid transparent;
}
.color-slot.selected { 
    border-color: #FFFFFF;
}
.color-slot.empty {
    background-color: #4b5563;
    background-image: linear-gradient(45deg, #374151 25%, transparent 25%, transparent 75%, #374151 75%, #374151), linear-gradient(45deg, #374151 25%, transparent 25%, transparent 75%, #374151 75%, #374151);
    background-size: 10px 10px;
    background-position: 0 0, 5px 5px;
}
#html-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
#html-color-picker::-webkit-color-swatch { border: none; border-radius: 0.375rem; }

#load-modal, #settings-modal {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
#load-modal > div,
#settings-modal > div {
    animation: slideInUp 0.3s ease-out forwards;
}
#modal-close-btn { font-size: 2.5rem; line-height: 1; font-weight: bold; }
#modal-content::-webkit-scrollbar { width: 8px; }
#modal-content::-webkit-scrollbar-track { background: #1f2937; }
#modal-content::-webkit-scrollbar-thumb { background-color: #4b5563; border-radius: 4px; border: 2px solid #1f2937; }
.save-item {
    background-color: #374151; border-left: 4px solid #4f46e5; padding: 0.75rem 1rem;
    border-radius: 0.375rem; margin-bottom: 0.75rem; cursor: pointer; transition: background-color 0.2s, border-color 0.2s;
}
.save-item:hover { background-color: #4b5563; border-left-color: #6366f1; }
.save-item p { margin: 0; color: #d1d5db; font-style: italic; }
.save-item .save-date { font-size: 0.8rem; color: #9ca3af; margin-top: 0.25rem; font-style: normal; }

#settings-modal-close-btn { font-size: 2.5rem; line-height: 1; font-weight: bold; }
.setting-item {
    display: flex; justify-content: space-between; align-items: center;
    background-color: #374151; padding: 0.75rem 1rem; border-radius: 0.5rem;
}
.toggle-switch { position: relative; display: inline-block; width: 60px; height: 34px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #4b5563; transition: .4s; border-radius: 34px; }
.toggle-switch .slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
.toggle-switch input:checked + .slider { background-color: #22c55e; }
.toggle-switch input:checked + .slider:before { transform: translateX(26px); }

.grid-container.bw-mode { border-color: #FFFFFF !important; }
.grid-container.bw-mode .grid-cell { background-color: #29313d !important; }
.grid-container.bw-mode .region-border-t { border-top-color: #FFFFFF !important; }
.grid-container.bw-mode .region-border-b { border-bottom-color: #FFFFFF !important; }
.grid-container.bw-mode .region-border-l { border-left-color: #FFFFFF !important; }
.grid-container.bw-mode .region-border-r { border-right-color: #FFFFFF !important; }
.grid-container.bw-mode .star-svg { color: #FFFFFF !important; }
.grid-container.bw-mode .x-svg { color: #EF4444 !important; }
.grid-container.bw-mode .dot-svg { color: #9ca3af !important; }
.grid-cell.error-star .star-svg { color: #EF4444 !important; }

@keyframes popIn { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideInUp { from { transform: translateY(25px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }


#solver-status {
    font-size: clamp(1.1rem, 3.5vw, 1.1rem);
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
}

.grid-container.solution-mode {
    border-color: #f59e0b !important;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.5);
}

.correct-star-pulse .star-svg {
  animation: pulse-green 1.2s ease-in-out;
  color: #f4f7f5;
}
@keyframes pulse-green {
  0% { transform: scale(1); }
  30% { transform: scale(1.3); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); }
}


/* Modal Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

/* Hide modal by default */
.hidden {
    display: none;
}

/* Modal Container */
.modal-container {
    position: relative;
    background-color: rgb(17 24 39);
    color: #f0f0f0;
    border-radius: 10px;
    padding: 30px 20px 25px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    text-align: center;
}

/* Modal Title */
.modal-container h2 {
    font-size: 28px;
    color: #4ade80; /* green accent */
    margin-bottom: 10px;
}

/* Time Display */
.modal-container p {
    font-size: 18px;
    color: #ccc;
    margin-bottom: 25px;
}

.modal-container span#time-taken {
    font-weight: bold;
    color: #fff;
}

/* Button Group */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* General Button Style */
.button-group button {
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

#play-another-btn {
    background-color: #16a34a; /* green */
    color: white;
}
#play-another-btn:hover {
    background-color: #15803d;
}

#change-level-btn {
    background-color: #1e40af; /* blue */
    color: white;
}
#change-level-btn:hover {
    background-color: #1e3a8a;
}

#go-home-btn {
    background-color: #4b5563; /* gray */
    color: white;
}
#go-home-btn:hover {
    background-color: #374151;
}

/* Close Button */
.close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 26px;
    color: #ccc;
    background: none;
    border: none;
    cursor: pointer;
}
.close-button:hover {
    color: white;
}

/* Share Button */
.share-button {
    position: absolute;
    top: 12px;
    left: 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: #ccc;
}
.share-button:hover {
    color: white;
}

#info-bar {
    /* Apply horizontal padding to the container instead of the children */
    padding-left: 25px;
    padding-right: 25px;
}

#info-bar > div:first-child,
#info-bar > div:last-child {
    /* This makes the left and right elements
       grow to occupy an equal amount of the leftover space. */
    flex: 1;
}

#info-bar > div:first-child {
    text-align: left;
}

#info-bar > div:last-child {
    text-align: right;
}

#info-bar > div:nth-child(2) {
    /* This prevents the timer from shrinking if the screen gets too narrow. */
    flex-shrink: 0;
}

/* Modal Stacking Order */
#success-modal {
	z-index: 100;
}
#puzzle-select-modal {
	z-index: 110;
}


