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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #050d18;
    font-family: 'Quicksand', sans-serif;
    color: #caf0f8;
}

body {
    background: radial-gradient(ellipse at center, #0a1628 0%, #050d18 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Palette reference: #0f2440 trench, #7b68ee jellyfish */

/* Grid Overlay */
.grid-overlay {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 180, 216, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 180, 216, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 1;
}

/* Scan Line */
.scan-line {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: rgba(0, 180, 216, 0.1);
    z-index: 100;
    pointer-events: none;
    animation: scanMove 6s linear infinite;
}

@keyframes scanMove {
    0% { top: 0; }
    100% { top: 100%; }
}

/* Bokeh */
.bokeh-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.bokeh-particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0;
    animation: bokehDrift var(--duration) ease-in-out infinite, bokehFadeIn 2s ease forwards;
    animation-delay: var(--delay);
}

@keyframes bokehDrift {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(var(--dx), calc(var(--dy) * -0.5)); }
    50% { transform: translate(calc(var(--dx) * -0.5), var(--dy)); }
    75% { transform: translate(calc(var(--dx) * 0.5), calc(var(--dy) * -0.3)); }
}

@keyframes bokehFadeIn {
    to { opacity: 1; }
}

/* Light rays */
body::before,
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

body::before {
    background: linear-gradient(35deg, transparent 40%, rgba(0, 180, 216, 0.04) 50%, transparent 60%);
}

body::after {
    background: linear-gradient(145deg, transparent 40%, rgba(0, 180, 216, 0.03) 50%, transparent 60%);
}

/* Bento Grid */
.bento-grid {
    position: relative;
    z-index: 10;
    width: 90vw;
    height: 85vh;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    grid-template-areas:
        "era era era clock"
        "kanji fact fact clock"
        "kanji links links pulse";
    gap: clamp(8px, 1.2vw, 14px);
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.bento-grid.visible {
    opacity: 1;
    transform: scale(1);
}

/* Cells */
.cell {
    background: rgba(15, 36, 64, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 180, 216, 0.2);
    border-radius: 12px;
    padding: clamp(1rem, 2vw, 1.5rem);
    position: relative;
    opacity: 0;
    transform: rotateY(90deg);
    transition: opacity 0.6s cubic-bezier(0.23, 1, 0.32, 1), transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.cell.revealed {
    opacity: 1;
    transform: rotateY(0deg);
}

.cell-era { grid-area: era; display: flex; align-items: center; justify-content: center; gap: 1.5rem; }
.cell-clock { grid-area: clock; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.cell-kanji { grid-area: kanji; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cell-fact { grid-area: fact; display: flex; flex-direction: column; justify-content: center; }
.cell-links { grid-area: links; display: flex; flex-direction: column; justify-content: center; }
.cell-pulse { grid-area: pulse; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* Corner brackets */
.corner-tl, .corner-tr, .corner-bl, .corner-br {
    position: absolute;
    width: 8px;
    height: 8px;
    border-color: rgba(0, 180, 216, 0.4);
    border-style: solid;
    border-width: 0;
}
.corner-tl { top: 4px; left: 4px; border-top-width: 1px; border-left-width: 1px; }
.corner-tr { top: 4px; right: 4px; border-top-width: 1px; border-right-width: 1px; }
.corner-bl { bottom: 4px; left: 4px; border-bottom-width: 1px; border-left-width: 1px; }
.corner-br { bottom: 4px; right: 4px; border-bottom-width: 1px; border-right-width: 1px; }

/* Era Cell */
.era-kanji {
    font-family: 'Zen Maru Gothic', sans-serif;
    font-size: clamp(4rem, 10vw, 9rem);
    font-weight: 500;
    color: #e8f1f2;
    letter-spacing: -0.02em;
    animation: eraPulse 4s ease-in-out infinite;
}

@keyframes eraPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.era-label {
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: clamp(0.875rem, 1.5vw, 1.25rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #90e0ef;
}

/* Clock Cell */
.clock-label {
    font-family: 'Share Tech', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #90e0ef;
    margin-bottom: 1rem;
}

.clock-readout {
    text-align: center;
}

.clock-line {
    font-family: 'Share Tech', sans-serif;
    font-size: clamp(1rem, 2vw, 1.5rem);
    color: #00b4d8;
    letter-spacing: 0.1em;
    padding: 0.4rem 0;
}

.clock-time {
    animation: secondsPulse 1s ease-in-out infinite;
}

@keyframes secondsPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.clock-sep {
    height: 1px;
    background: rgba(0, 180, 216, 0.15);
    width: 100%;
}

/* Kanji Cell */
.kanji-label, .fact-label, .links-label, .pulse-label {
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: clamp(0.65rem, 1vw, 0.85rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #90e0ef;
    margin-bottom: 0.75rem;
}

.card-container {
    width: 100%;
    flex: 1;
    perspective: 800px;
    position: relative;
}

.card-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.6s;
    border-radius: 8px;
}

.card-back {
    transform: rotateY(180deg);
}

.card-container.flipped .card-front {
    transform: rotateY(180deg);
    box-shadow: 0 0 20px rgba(0, 180, 216, 0.4);
}

.card-container.flipped .card-back {
    transform: rotateY(0deg);
    box-shadow: 0 0 20px rgba(0, 180, 216, 0.4);
}

.kanji-display {
    font-family: 'Zen Maru Gothic', sans-serif;
    font-size: clamp(3rem, 6vw, 5rem);
    font-weight: 500;
    color: #e8f1f2;
}

.kanji-meaning {
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #90e0ef;
    margin-top: 0.5rem;
}

/* Fact Cell */
.fact-text {
    font-family: 'Quicksand', sans-serif;
    font-weight: 400;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    line-height: 1.65;
    color: #caf0f8;
}

.fact-text .highlight {
    color: #e07a5f;
    font-weight: 600;
}

/* Links Cell */
.links-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.pill-link {
    font-family: 'Nunito', sans-serif;
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    color: #90e0ef;
    text-decoration: none;
    border: 1px solid rgba(0, 180, 216, 0.3);
    border-radius: 999px;
    padding: 0.4rem 1rem;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.pill-link:hover {
    background: rgba(0, 180, 216, 0.15);
    color: #e8f1f2;
    border-color: #00b4d8;
}

/* Pulse / Sonar */
.sonar-svg {
    width: 80%;
    max-width: 150px;
    height: auto;
}

.sonar-center {
    fill: #00b4d8;
}

.sonar-ring {
    fill: none;
    stroke: #00b4d8;
    stroke-width: 1.5;
    opacity: 0;
    animation: sonarExpand 6s ease-out infinite;
}

.ring-2 { animation-delay: 2s; }
.ring-3 { animation-delay: 4s; }

@keyframes sonarExpand {
    0% { r: 10; opacity: 0.6; stroke-width: 1.5; }
    100% { r: 90; opacity: 0; stroke-width: 0.5; }
}

/* Responsive */
@media (max-width: 768px) {
    .bento-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "era era"
            "kanji clock"
            "fact fact"
            "links pulse";
        width: 95vw;
        height: auto;
        min-height: 90vh;
    }

    .cell {
        transform: rotateX(90deg);
    }
    .cell.revealed {
        transform: rotateX(0deg);
    }
    .card-container.flipped .card-front {
        transform: rotateX(180deg);
    }
    .card-container.flipped .card-back {
        transform: rotateX(0deg);
    }
    .card-back {
        transform: rotateX(180deg);
    }
}

@media (max-width: 480px) {
    .bento-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "era"
            "clock"
            "kanji"
            "fact"
            "links"
            "pulse";
    }
}
