:root {
    --cols: 1;
    --rows: 1;
    --gap: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: #000;
    overflow: hidden;
}

#screen {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    gap: var(--gap);
    padding: var(--gap);
    width: 100vw;
    height: 100vh;
}

.tile {
    grid-column: var(--x) / span var(--w);
    grid-row: var(--y) / span var(--h);
    position: relative; /* contains absolutely-positioned content within the tile */
    min-width: 0;       /* let the cell shrink below its content's intrinsic size */
    min-height: 0;
    overflow: hidden;   /* clip anything that exceeds the tile */
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    background: #111;
    color: #eee;
    font-family: ui-sans-serif, system-ui, sans-serif;
}

/* Content fills the tile. */
.tile > * {
    width: 100%;
    height: 100%;
    display: block;
}

/* The wrapper holds the server-rendered content; its single root fills it. */
.tile-content > * {
    width: 100%;
    height: 100%;
}

/* Manual-delete cross in the top-left corner (overrides the fill rule above). */
.tile > .tile-delete {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    width: 1.6rem;
    height: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
}

.tile > .tile-delete:hover {
    opacity: 1;
    background: #c0392b;
}

/* Timeout indicator, same shape/size/position style as the cross, just right
   of it. Timed tiles show a pie that spins down to empty; permanent tiles ∞. */
@property --pie {
    syntax: '<angle>';
    inherits: false;
    initial-value: 360deg;
}

.tile > .tile-status {
    position: absolute;
    top: 6px;
    left: calc(6px + 1.6rem + 6px);
    z-index: 2;
    width: 1.6rem;
    height: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    opacity: 0.45;
}

/* Permanent: dark disc with the ∞ glyph. */
.tile-status[data-mode='permanent'] {
    background: rgba(0, 0, 0, 0.55);
}

/* Timed: white pie over a dark remainder; --pie shrinks 360deg -> 0deg. */
.tile-status[data-mode='timed'] {
    background: conic-gradient(#fff var(--pie), rgba(0, 0, 0, 0.5) 0);
}

@keyframes tile-spin-down {
    from { --pie: 360deg; }
    to { --pie: 0deg; }
}


.tile img,
.tile video {
    object-fit: cover;
}

.tile iframe {
    border: 0;
}

.tile .text {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5em;
    font-size: clamp(1rem, 4vh, 4rem);
    line-height: 1.2;
}

.tile .html {
    overflow: auto;
}

/* An unknown content type renders visibly, never as a blank cell. */
.tile .unknown {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #a00;
    text-align: center;
    padding: 0.5em;
}
