/* 対称ゲーム — 和モダン・インクグロー */

:root {
    --ink: #1c1a17;
    --ink-soft: #3a3530;
    --paper: #f2ebe0;
    --paper-deep: #e6dccb;
    --seal: #b8321a;
    --seal-deep: #8c2412;
    --glow: rgba(184, 50, 26, 0.35);
    --line: rgba(28, 26, 23, 0.18);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

::selection {
    background: transparent;
    color: inherit;
}

html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    height: -webkit-fill-available;
    height: 100dvh;
    overscroll-behavior: none;
}

body {
    font-family: "Hiragino Mincho ProN", "Yu Mincho", "Hiragino Mincho Pro",
        "Noto Serif JP", "Shippori Mincho", "Times New Roman", serif;
    background:
        radial-gradient(120% 80% at 50% 0%, #fff8ee 0%, transparent 55%),
        linear-gradient(160deg, #efe6d6 0%, #d9cdba 48%, #cfc3ae 100%);
    color: var(--ink);
    display: flex;
    justify-content: center;
    align-items: stretch;
    height: 100%;
    height: 100dvh;
    padding:
        max(6px, var(--safe-top))
        max(8px, var(--safe-right))
        max(8px, var(--safe-bottom))
        max(8px, var(--safe-left));
    transition: background 0.6s ease, color 0.4s ease;
}

.paper-grain {
    pointer-events: none;
    position: fixed;
    inset: 0;
    opacity: 0.22;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(80, 60, 40, 0.03) 2px,
            rgba(80, 60, 40, 0.03) 3px
        ),
        radial-gradient(circle at 20% 30%, rgba(90, 70, 40, 0.08), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(60, 40, 20, 0.07), transparent 45%);
    z-index: 0;
    mix-blend-mode: multiply;
}

body.neon-mode {
    background:
        radial-gradient(circle at 50% 35%, #3a2018 0%, #120e0c 55%, #050403 100%);
    color: #f3ebe2;
}

body.neon-mode .paper-grain {
    opacity: 0.35;
    mix-blend-mode: soft-light;
}

.game-container {
    position: relative;
    z-index: 1;
    width: min(600px, 100%);
    height: 100%;
    max-height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px 10px;
    background:
        linear-gradient(180deg, rgba(255, 252, 246, 0.92), rgba(242, 235, 224, 0.88));
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.55) inset,
        0 18px 40px rgba(40, 28, 16, 0.18);
    overflow: hidden;
    transition: background 0.5s ease, box-shadow 0.5s ease, border-color 0.5s ease;
}

body.neon-mode .game-container {
    background: linear-gradient(180deg, rgba(28, 20, 18, 0.92), rgba(12, 10, 9, 0.94));
    border-color: rgba(255, 210, 180, 0.12);
    box-shadow:
        0 0 0 1px rgba(184, 50, 26, 0.2),
        0 0 48px rgba(184, 50, 26, 0.18);
}

.brand {
    flex: 0 0 auto;
    text-align: center;
    padding: 0 4px;
}

.brand-mark {
    display: inline-block;
    margin-bottom: 2px;
    padding: 2px 8px 1px;
    border: 1.5px solid var(--seal);
    color: var(--seal);
    font-size: 0.64rem;
    letter-spacing: 0.35em;
    line-height: 1.35;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(184, 50, 26, 0.15);
    animation: seal-breathe 3.6s ease-in-out infinite;
}

body.neon-mode .brand-mark {
    border-color: #ff6a4a;
    color: #ffb39f;
    box-shadow: 0 0 18px rgba(255, 90, 60, 0.35);
}

@keyframes seal-breathe {
    0%, 100% { box-shadow: 0 0 0 1px rgba(184, 50, 26, 0.12); }
    50% { box-shadow: 0 0 14px rgba(184, 50, 26, 0.28); }
}

h1 {
    font-size: clamp(1.05rem, 3.8vw, 1.45rem);
    font-weight: 600;
    letter-spacing: 0.22em;
    color: var(--ink);
    margin-bottom: 0;
}

body.neon-mode h1 {
    color: #f7efe6;
    text-shadow: 0 0 18px rgba(255, 120, 80, 0.35);
}

.instruction {
    display: none;
}

.canvas-container {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    background: #faf6ef;
    border-radius: 4px;
    padding: 10px;
    box-shadow: inset 0 0 0 1px rgba(40, 30, 20, 0.1);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.35s ease, box-shadow 0.35s ease;
}

.ink-frame {
    pointer-events: none;
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(40, 30, 20, 0.16);
    border-radius: 2px;
    box-shadow:
        inset 0 0 0 3px rgba(242, 235, 224, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.35);
    z-index: 1;
}

body.neon-mode .canvas-container {
    background: #050403;
    box-shadow:
        inset 0 0 0 1px rgba(255, 180, 140, 0.12),
        0 0 28px rgba(184, 50, 26, 0.18);
}

body.neon-mode .ink-frame {
    border-color: rgba(255, 170, 130, 0.22);
    box-shadow:
        inset 0 0 24px rgba(184, 50, 26, 0.12),
        0 0 18px rgba(255, 90, 60, 0.12);
}

#gameCanvas {
    position: relative;
    z-index: 0;
    display: block;
    /* 正方形を縦横どちらかで潰さない（下切れの主因） */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    margin: 0 auto;
    border: none;
    border-radius: 2px;
    cursor: crosshair;
    background: #faf6ef;
    transition: filter 0.1s ease;
}

#gameCanvas.brush-mode {
    cursor: none;
}

.brush-cursor {
    position: absolute;
    z-index: 5;
    width: 36px;
    height: 36px;
    margin-left: -6px;
    margin-top: -30px;
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(40, 28, 16, 0.35));
    transform: rotate(-28deg);
    transition: opacity 0.12s ease;
}

.brush-cursor.is-drawing {
    opacity: 0.95;
    filter: drop-shadow(0 0 6px rgba(184, 50, 26, 0.45));
}

body.neon-mode .brush-cursor svg path[fill="#1c1a17"] {
    fill: #f3ebe2;
}

body.neon-mode #gameCanvas {
    background: transparent;
}

#gameCanvas.beat-hit {
    filter: brightness(1.25) contrast(1.1) saturate(1.05);
}

.status-bar {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
}

.track-chip span {
    max-width: 9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 252, 246, 0.7);
    color: var(--ink-soft);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
}

.status-chip span {
    color: var(--seal);
    font-weight: 600;
    letter-spacing: 0.08em;
}

body.neon-mode .status-chip {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 200, 170, 0.16);
    color: #d9cfc4;
}

body.neon-mode .status-chip span {
    color: #ff9a7e;
}

.controls {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding-bottom: 0;
}

.seal-btn,
.play-btn,
.mute-btn {
    appearance: none;
    border: 1.5px solid var(--ink);
    background:
        linear-gradient(180deg, rgba(255, 252, 246, 0.95), rgba(236, 226, 210, 0.92));
    color: var(--ink);
    min-height: 48px;
    min-width: 48px;
    padding: 8px 6px;
    border-radius: 3px;
    font-family: inherit;
    font-size: clamp(0.72rem, 2.6vw, 0.84rem);
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1.25;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    will-change: transform;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.55) inset,
        0 2px 8px rgba(40, 28, 16, 0.08);
    transition:
        transform 0.08s ease,
        opacity 0.08s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease,
        background 0.2s ease,
        color 0.2s ease;
}

.seal-btn:hover,
.play-btn:hover,
.mute-btn:hover {
    box-shadow:
        0 0 0 1px rgba(184, 50, 26, 0.2),
        0 0 16px var(--glow);
    border-color: var(--seal);
}

.seal-btn:active,
.play-btn:active,
.mute-btn:active,
.seal-btn.is-pressed,
.play-btn.is-pressed,
.mute-btn.is-pressed {
    transform: scale(0.92);
    opacity: 0.88;
}

.mute-btn {
    position: fixed;
    top: max(8px, var(--safe-top));
    right: max(8px, var(--safe-right));
    z-index: 20;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.1rem;
    letter-spacing: 0;
    line-height: 1;
    background: rgba(255, 252, 246, 0.92);
}

body.neon-mode .mute-btn {
    background: rgba(28, 20, 18, 0.9);
    border-color: rgba(255, 210, 180, 0.35);
    color: #f0e6dc;
}

.seal-accent {
    border-color: var(--seal);
    color: var(--seal-deep);
    box-shadow:
        0 0 0 1px rgba(184, 50, 26, 0.12),
        0 0 12px rgba(184, 50, 26, 0.12);
}

.ink-palette {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: center;
    gap: 2px;
    min-height: 48px;
    min-width: 0;
    padding: 4px 3px;
    border: 1.5px solid var(--seal);
    border-radius: 3px;
    background:
        linear-gradient(180deg, rgba(255, 252, 246, 0.95), rgba(236, 226, 210, 0.92));
    box-shadow:
        0 0 0 1px rgba(184, 50, 26, 0.12),
        0 2px 8px rgba(40, 28, 16, 0.08);
}

.ink-swatch {
    appearance: none;
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1.25;
    max-height: 36px;
    min-height: 22px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(28, 26, 23, 0.28);
    border-radius: 50% 50% 48% 48% / 42% 42% 58% 58%;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        inset 0 -3px 4px rgba(0, 0, 0, 0.18),
        inset 0 2px 2px rgba(255, 255, 255, 0.25);
    transition: transform 0.08s ease, box-shadow 0.12s ease, opacity 0.08s ease;
}

.ink-swatch::after {
    content: "";
    position: absolute;
    left: 22%;
    top: 16%;
    width: 34%;
    height: 28%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    pointer-events: none;
}

.ink-swatch:active,
.ink-swatch.is-pressed {
    transform: scale(0.88);
    opacity: 0.9;
}

.ink-swatch.is-selected {
    outline: 2px solid var(--ink);
    outline-offset: 1px;
    box-shadow:
        0 0 0 1px rgba(255, 252, 246, 0.9),
        0 0 10px rgba(184, 50, 26, 0.35),
        inset 0 -3px 4px rgba(0, 0, 0, 0.18);
    z-index: 1;
}

body.neon-mode .ink-palette {
    background: rgba(255, 255, 255, 0.04);
    border-color: #ff6a4a;
}

body.neon-mode .ink-swatch.is-selected {
    outline-color: #ffb39f;
}

.seal-muted {
    opacity: 0.82;
    border-style: dashed;
}

.play-btn {
    grid-column: 1 / -1;
    border-color: var(--seal);
    background: linear-gradient(135deg, var(--seal) 0%, var(--seal-deep) 100%);
    color: #fff8f4;
    letter-spacing: 0.28em;
    font-size: clamp(0.9rem, 3vw, 1.05rem);
    box-shadow:
        0 0 0 1px rgba(184, 50, 26, 0.25),
        0 8px 22px rgba(184, 50, 26, 0.28);
}

.play-btn.playing {
    background: linear-gradient(135deg, #1c1a17 0%, #3a2018 100%);
    border-color: #ff6a4a;
    animation: ink-pulse 0.7s ease-in-out infinite alternate;
}

@keyframes ink-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 12px rgba(255, 90, 60, 0.25);
    }
    100% {
        transform: scale(1.02);
        box-shadow: 0 0 28px rgba(255, 140, 80, 0.45);
    }
}

body.neon-mode .seal-btn {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 210, 180, 0.28);
    color: #f0e6dc;
    box-shadow: none;
}

body.neon-mode .seal-accent {
    border-color: #ff6a4a;
    color: #ffb39f;
}

body.neon-mode .play-btn:not(.playing) {
    background: linear-gradient(135deg, #c23b22 0%, #7a1f12 100%);
}

@media (max-width: 420px) {
    .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .play-btn {
        grid-column: 1 / -1;
        min-height: 42px;
        letter-spacing: 0.2em;
    }

    .game-container {
        gap: 5px;
        padding: 6px 8px 8px;
    }

    .brand-mark {
        font-size: 0.6rem;
        margin-bottom: 1px;
    }
}

@media (min-width: 520px) {
    .controls {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
