:root {
    --grid-columns: 6;
    --grid-row-height: 100px;
    --gap: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    height: 100vh;
    touch-action: manipulation;
}

#grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), var(--grid-cell-width, 100px));
    grid-auto-rows: var(--grid-row-height);
    gap: var(--gap);
    padding: var(--gap);
    justify-content: center;
    align-content: center;
    height: 100vh;
}

/* -- Widget base -- */

.widget {
    background: #333;
    border: 1px solid #4a4a4a;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, background-color 0.1s;
    position: relative;
    overflow: hidden;
    container-type: inline-size;
}

.widget:active {
    transform: scale(0.95);
    background: #444;
}

.widget.no-action {
    cursor: default;
}
.widget.no-action:active {
    transform: none;
    background: #333;
}

/* -- Widget contents -- */

.widget .icon {
    flex: 1;
    width: 100%;
    min-height: 0;
    object-fit: contain;
    padding: 8px;
    opacity: 0.9;
}

.widget .label {
    color: #ddd;
    font-size: 12px;
    text-align: center;
    line-height: 1.2;
    padding: 0 4px;
}

.widget .data-display {
    color: #fff;
    font-size: 22px;
    font-weight: 600;
}

/* State indicator: glow when on */
.widget.state-on {
    border-color: rgba(255, 180, 50, 0.8);
    box-shadow: 0 0 18px 4px rgba(255, 180, 50, 0.45), inset 0 0 8px rgba(255, 180, 50, 0.1);
    transition: box-shadow 0.4s, border-color 0.4s;
}

/* Printer status border (multi-color, driven by --ps-color / --ps-glow) */
.widget[data-printer-status] {
    border-color: var(--ps-color);
    box-shadow: 0 0 18px 4px var(--ps-glow),
                inset 0 0 8px var(--ps-glow);
    transition: border-color 0.4s, box-shadow 0.4s;
}

@keyframes printer-status-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.widget.printer-status-pulse {
    animation: printer-status-pulse 1.5s ease-in-out infinite;
}

/* Gauge template */
.widget .gauge {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: conic-gradient(#4caf50 0%, #333 0%);
}
/* Analog Clock */
.widget .clock-container {
    position: relative;
    width: 92%;
    aspect-ratio: 1;
    border: 4px solid #555;
    border-radius: 50%;
    background: #222;
}

.widget .clock-face {
    position: relative;
    width: 100%;
    height: 100%;
}

.widget .clock-hand {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform-origin: bottom center;
    border-radius: 4px;
    z-index: 4;
}

.widget .hand-hour {
    width: 6px;
    height: 25%;
    background: #eee;
    margin-left: -3px;
}

.widget .hand-minute {
    width: 5px;
    height: 42%;
    background: #ccc;
    margin-left: -2.5px;
}

.widget .hand-second {
    width: 2px;
    height: 40%;
    background: #ff4444;
    margin-left: -1px;
}

.widget .clock-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.widget .clock-face {
    position: relative;
    width: 100%;
    height: 100%;
}

.widget .clock-marker {
    position: absolute;
    top: 0;
    left: 50%;
    width: 0;
    height: 50%;
    transform-origin: bottom center;
}

.widget .marker-tick {
    width: 4px;
    height: 12%;
    background: #666;
    margin-left: -2px;
}

.widget .marker-tick-small {
    width: 2px;
    height: 6%;
    background: #444;
    margin-left: -1px;
}


/* Keyboard shortcut hint */
.widget .key-hint {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 10px;
    color: #555;
    font-family: monospace;
}

/* Camera image template */
.widget .cam-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 11px;
    opacity: 0.9;
}
/* Label on top of camera image */
.widget:has(.cam-image) .label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 0 0 11px 11px;
    color: #eee;
    font-size: 11px;
    text-align: center;
    z-index: 1;
}

/* Big Text (Calendar) */
.widget .big-text {
    font-size: 50cqw;
    font-weight: 700;
    color: #fff;
    line-height: 0.9;
}

.widget .big-text-sub {
    font-size: 18cqw;
    font-weight: 600;
    text-transform: lowercase;
    color: #888;
}

.widget .big-text-sub.top {
    margin-bottom: -2cqw;
    color: #ff4444; /* Accent for month */
}

.widget .big-text-sub.bottom {
    margin-top: -2cqw;
}

/* Weather Detailed */
.widget .weather-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 8px;
    z-index: 2;
}

.widget .weather-icon-bg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    z-index: 1;
    font-size: 60cqw;
    pointer-events: none;
    background: #000;
}

.widget .weather-current {
    flex: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42cqw;
    font-weight: 600;
    color: #fff;
    width: 90%;
    margin-top: 4cqw;
}

.widget .weather-sub {
    flex: 1;
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    padding-bottom: 2cqw;
}

.widget .weather-sub-val {
    font-size: 20cqw;
    font-weight: 700;
}

.widget .weather-low { color: #4facfe; }
.widget .weather-high { color: #ff4b2b; }

.widget .weather-sub-label {
    display: none;
}

/* Responsive column overrides are handled by JS auto-sizing */

/* Action feedback flash */
@keyframes flash-success { 0%,100% { background: #333; } 50% { background: #2a6; } }
@keyframes flash-error    { 0%,100% { background: #333; } 50% { background: #a33; } }
.widget.flash-success { animation: flash-success 0.3s ease; }
.widget.flash-error   { animation: flash-error   0.3s ease; }

/* -- Key overlay (? to toggle) -- */

#key-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 50;
}

.key-overlay-badge {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: monospace;
    font-weight: 900;
    color: #FFCC33;
    border: 2px solid rgba(255, 204, 51, 0.4);
    border-radius: 12px;
    box-sizing: border-box;
    pointer-events: none;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
