:root {
    --tile: 240px;
    --gap: 10px;
    --bg: #0a0a0a;
    --fg: #f5f5f5;
    --muted: #888;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

header {
    padding: 32px 24px 16px;
    max-width: 720px;
}

header h1 {
    margin: 0 0 14px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

header .lede {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: #ccc;
}

header .lede a {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: rgba(255, 255, 255, 0.35);
    white-space: nowrap;
}

header .lede a:hover {
    text-decoration-color: #fff;
}

#grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
    gap: var(--gap);
    padding: 16px 24px 64px;
}

.tile {
    position: relative;
    aspect-ratio: 1;
    background: #111;
    overflow: hidden;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    isolation: isolate;
}

.tile img,
.tile video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tile video {
    opacity: 0;
    transition: opacity 180ms ease;
}

.tile::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.tile.active::after {
    opacity: 0;
}

.tile.active video {
    opacity: 1;
}

.tile.disabled {
    cursor: default;
}

.tile.disabled img {
    filter: grayscale(1) brightness(0.5);
    opacity: 0.6;
}

.tile.disabled .label {
    color: #aaa;
    background: rgba(0, 0, 0, 0.7);
}

.tile .play-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 2;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
}

.tile .play-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    grid-area: 1 / 1;
}

.tile .play-btn .i-pause { display: none; }
.tile.active .play-btn .i-play { display: none; }
.tile.active .play-btn .i-pause { display: block; }

.tile .label {
    position: absolute;
    left: 8px;
    bottom: 8px;
    z-index: 2;
    font-size: 10px;
    font-weight: 500;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 4px 7px;
    border-radius: 3px;
    letter-spacing: 0.02em;
    pointer-events: none;
}

#writeup {
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    background: #0e0e0e;
    color: var(--fg);
    padding: 0;
    max-width: 760px;
    width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    overflow: hidden;
    flex-direction: column;
}

/* Only apply `display: flex` when the dialog is open so the browser's
   `dialog:not([open]) { display: none }` still hides the closed state.
   Without this override, the higher-specificity #writeup rule keeps the
   dialog visible after `dlg.close()`. */
#writeup[open] {
    display: flex;
}

#writeup::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-bar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #0e0e0e;
    border-bottom: 1px solid #1f1f1f;
}

.modal-title {
    flex: 1;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.modal-copy {
    font: inherit;
    font-size: 12px;
    padding: 6px 12px;
    background: #1c1c1c;
    color: #fff;
    border: 1px solid #2a2a2a;
    border-radius: 4px;
    cursor: pointer;
    transition: background 120ms, color 120ms;
}

.modal-copy:hover {
    background: #262626;
}

.modal-copy.copied {
    background: #1f3a1f;
    border-color: #2e552e;
    color: #b3eab3;
}

.modal-close {
    width: 28px;
    height: 28px;
    background: transparent;
    color: #aaa;
    border: 0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
}

.modal-close:hover {
    background: #1c1c1c;
    color: #fff;
}

.modal-body {
    padding: 20px 28px 40px;
    overflow: auto;
    font-size: 14px;
    line-height: 1.6;
    color: #d4d4d4;
}

.modal-body h1, .modal-body h2, .modal-body h3, .modal-body h4 {
    color: #fff;
    margin: 28px 0 10px;
    font-weight: 600;
    line-height: 1.3;
}

.modal-body h1 { font-size: 22px; margin-top: 6px; }
.modal-body h2 { font-size: 16px; text-transform: uppercase; letter-spacing: 0.06em; color: #ccc; margin-top: 32px; }
.modal-body h3 { font-size: 14px; color: #eee; }
.modal-body h4 { font-size: 13px; color: #ccc; }
.modal-body p { margin: 0 0 14px; }
.modal-body ul, .modal-body ol { margin: 0 0 14px; padding-left: 22px; }
.modal-body li { margin: 4px 0; }
.modal-body a { color: #9ad; }
.modal-body strong { color: #fff; }
.modal-body code {
    background: #1c1c1c;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 12.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #f0c674;
}
.modal-body pre {
    background: #161616;
    border: 1px solid #232323;
    border-radius: 6px;
    padding: 14px 16px;
    overflow: auto;
    font-size: 12.5px;
    line-height: 1.5;
    margin: 0 0 16px;
}
.modal-body pre code {
    background: transparent;
    padding: 0;
    color: #ddd;
    font-size: inherit;
}
.modal-body table {
    border-collapse: collapse;
    margin: 0 0 16px;
    font-size: 13px;
    width: 100%;
}
.modal-body th, .modal-body td {
    padding: 6px 10px;
    border-bottom: 1px solid #232323;
    text-align: left;
    vertical-align: top;
}
.modal-body th { color: #fff; font-weight: 600; }
.modal-body hr {
    border: 0;
    border-top: 1px solid #232323;
    margin: 24px 0;
}

@media (max-width: 640px) {
    .modal-body { padding: 16px 18px 32px; font-size: 13.5px; }
    .modal-body h1 { font-size: 20px; }
}

@media (max-width: 640px) {
    :root { --tile: 160px; --gap: 6px; }
    header { padding: 24px 16px 12px; }
    #grid { padding: 12px 16px 48px; }
}
