:root {
    --bg-main: #070b14;
    --panel-bg: rgba(15, 21, 36, 0.9);
    --panel-border: rgba(112, 227, 255, 0.22);
    --text-main: #eef4ff;
    --text-sub: #b8c9df;
    --accent: #39d0ff;
    --accent-strong: #17a9e8;
    --danger: #ff5e7f;
    --good: #6dff97;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    font-family: 'Noto Sans JP', sans-serif;
    background:
        radial-gradient(circle at 20% -10%, rgba(25, 160, 255, 0.28), transparent 45%),
        radial-gradient(circle at 80% 0%, rgba(255, 94, 127, 0.24), transparent 50%),
        linear-gradient(180deg, #080b16, #03050b 60%);
    color: var(--text-main);
    padding-bottom: env(safe-area-inset-bottom);
}

.app-shell {
    width: min(1120px, 94vw);
    margin: 28px auto 40px;
    display: grid;
    gap: 16px;
}

.top-header {
    padding: 20px 24px;
    border-radius: 16px;
    background: linear-gradient(140deg, rgba(10, 22, 42, 0.92), rgba(18, 11, 30, 0.9));
    border: 1px solid var(--panel-border);
}

.top-header h1 {
    margin: 0;
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.9rem, 4vw, 2.6rem);
    letter-spacing: 0.06em;
}

.top-header p {
    margin: 8px 0 0;
    color: var(--text-sub);
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 1.15rem;
}

.scanner-grid,
.generator-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 14px;
}

.preview-wrap {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #05080f;
    border: 1px solid rgba(255, 255, 255, 0.12);
    min-height: 320px;
}

#camera,
.camera-placeholder {
    width: 100%;
    height: 100%;
    min-height: 320px;
}

#camera {
    object-fit: cover;
    display: none;
}

.camera-placeholder {
    display: grid;
    place-items: center;
    color: var(--text-sub);
    letter-spacing: 0.08em;
    font-family: 'Orbitron', sans-serif;
}

#decode-canvas {
    display: none;
}

.scanner-controls {
    display: grid;
    gap: 10px;
    align-content: start;
}

.btn-row {
    display: flex;
    gap: 8px;
}

button,
.file-label {
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.92rem;
    font-weight: 700;
    color: #06152a;
    background: linear-gradient(135deg, var(--accent), #8bf3ff);
    cursor: pointer;
    transition: transform 0.18s ease, filter 0.18s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button:hover,
.file-label:hover {
    transform: translateY(-1px);
    filter: brightness(1.04);
}

button.ghost {
    background: rgba(135, 183, 221, 0.16);
    color: var(--text-main);
    border: 1px solid rgba(180, 214, 243, 0.35);
}

.file-label {
    text-align: center;
}

input[type="file"] {
    display: none;
}

textarea {
    width: 100%;
    resize: vertical;
    border-radius: 8px;
    border: 1px solid rgba(171, 209, 255, 0.33);
    background: rgba(3, 11, 20, 0.6);
    color: var(--text-main);
    padding: 10px;
}

.detector-note {
    color: var(--text-sub);
    font-size: 0.85rem;
    min-height: 20px;
}

.scan-result {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(0, 8, 18, 0.58);
    border-radius: 10px;
    line-height: 1.8;
}

.product-panel {
    margin-top: 10px;
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(5, 14, 28, 0.7);
    border: 1px solid rgba(146, 201, 236, 0.25);
}

.product-status {
    margin: 0 0 8px;
    font-size: 0.86rem;
    color: #cde4ff;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 14px;
    font-size: 0.88rem;
}

.label {
    color: var(--text-sub);
}

.fighter-card {
    border-radius: 12px;
    padding: 16px;
    background:
        radial-gradient(circle at 10% 10%, rgba(57, 208, 255, 0.25), transparent 35%),
        radial-gradient(circle at 90% 90%, rgba(255, 94, 127, 0.25), transparent 40%),
        rgba(5, 12, 23, 0.92);
    border: 1px solid rgba(150, 209, 245, 0.24);
}

.fighter-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.fighter-head h3 {
    margin: 0;
    font-size: 1.3rem;
}

.rank-chip {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.fighter-card p {
    margin: 10px 0;
}

.stat-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.stat-list div {
    border-radius: 8px;
    background: rgba(145, 207, 255, 0.1);
    padding: 8px;
}

.fighter-desc {
    color: var(--text-sub);
    font-size: 0.9rem;
    min-height: 44px;
}

.generator-actions {
    display: grid;
    gap: 10px;
    align-content: start;
}

.collection-sub {
    margin: 0 0 12px;
    color: var(--text-sub);
    font-size: 0.92rem;
}

.collection-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}

.collection-item {
    padding: 12px;
    border-radius: 10px;
    background: rgba(6, 14, 28, 0.72);
    border: 1px solid rgba(140, 204, 247, 0.2);
    display: grid;
    gap: 8px;
}

.collection-item h4 {
    margin: 0;
    font-size: 1rem;
}

.collection-item .mini {
    font-size: 0.82rem;
    color: var(--text-sub);
}

.collection-list > .mini {
    margin: 0;
    color: var(--text-sub);
}

.collection-actions {
    display: flex;
    gap: 8px;
}

.collection-actions button {
    flex: 1;
    padding: 8px;
    font-size: 0.82rem;
    min-height: 42px;
}

.hud {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 10px;
}

.hp-group {
    display: grid;
    gap: 4px;
}

.hp-group.enemy {
    text-align: right;
}

.hp-group span {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 0.06em;
}

.hp-bar {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    overflow: hidden;
}

.hp-bar span {
    display: block;
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #6eff9e, #dfff5d);
    transition: width 0.2s ease;
}

#battle-canvas {
    width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid rgba(152, 214, 252, 0.24);
    background: linear-gradient(180deg, #21325d 0%, #141a36 52%, #0a1125 100%);
}

.battle-stage {
    overflow: hidden;
    border-radius: 10px;
    position: relative;
}

.battle-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: grid;
    place-content: center;
    text-align: center;
    opacity: 0;
    transition: opacity 0.18s ease;
    z-index: 4;
}

.battle-overlay.active {
    opacity: 1;
}

.battle-overlay.phase-round,
.battle-overlay.phase-ready,
.battle-overlay.phase-fight,
.battle-overlay.phase-ko,
.battle-overlay.phase-result {
    background:
        linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, transparent 24%, transparent 76%, rgba(0, 0, 0, 0.5) 100%);
}

.battle-main-text {
    margin: 0;
    padding: 0;
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: clamp(2rem, 8vw, 4.4rem);
    letter-spacing: 0.12em;
    color: #f8fcff;
    text-shadow:
        0 0 16px rgba(120, 225, 255, 0.75),
        0 2px 0 rgba(0, 0, 0, 0.5);
}

.battle-sub-text {
    margin-top: 6px;
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.8rem, 2.6vw, 1.25rem);
    letter-spacing: 0.08em;
    color: #d8ebff;
}

.battle-overlay.phase-fight .battle-main-text {
    color: #ffe87a;
    animation: fightPulse 0.35s ease 2;
}

.battle-overlay.phase-ready .battle-main-text {
    color: #d6ecff;
}

.battle-overlay.phase-ko .battle-main-text {
    color: #ff7596;
    text-shadow:
        0 0 20px rgba(255, 94, 127, 0.85),
        0 2px 0 rgba(0, 0, 0, 0.55);
    transform: scale(1.06);
}

.battle-overlay.phase-result .battle-main-text {
    color: #fff6b0;
    text-shadow:
        0 0 20px rgba(255, 232, 122, 0.8),
        0 2px 0 rgba(0, 0, 0, 0.6);
}

.battle-winner-banner {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    min-width: min(88%, 560px);
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 235, 145, 0.55);
    background: linear-gradient(90deg, rgba(17, 31, 58, 0.86), rgba(53, 26, 41, 0.86));
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 5;
}

.battle-winner-banner.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.winner-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    color: #ffe87a;
}

#battle-winner-name {
    font-size: 1rem;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.winner-side {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    color: #b4def9;
}

@keyframes fightPulse {
    0% {
        transform: scale(0.82);
        opacity: 0.3;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.controls-info {
    margin: 10px 0 6px;
    color: var(--text-sub);
    font-size: 0.9rem;
}

.mobile-controls {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
        'move action'
        'quick quick';
    gap: 8px;
    margin-bottom: 10px;
}

.gesture-zone {
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(8, 20, 38, 0.86);
    border: 1px solid rgba(151, 210, 250, 0.32);
    color: #deefff;
    display: grid;
    gap: 4px;
    touch-action: none;
    user-select: none;
}

.gesture-zone strong {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.92rem;
    letter-spacing: 0.08em;
}

.gesture-zone span {
    font-size: 0.75rem;
    color: #b5cae3;
}

.gesture-zone.is-active {
    border-color: rgba(98, 229, 255, 0.95);
    background: rgba(13, 37, 68, 0.95);
}

.move-zone {
    grid-area: move;
}

.action-zone {
    grid-area: action;
}

.mobile-quick-actions {
    grid-area: quick;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.mobile-quick-actions button {
    min-height: 50px;
    padding: 10px 0;
    font-size: 0.96rem;
    font-family: 'Orbitron', sans-serif;
}

.mobile-quick-actions button:active {
    transform: translateY(1px) scale(0.98);
}

.battle-log {
    margin: 8px 0 0;
    min-height: 24px;
    color: #d7e7ff;
}

.meta-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    color: var(--text-sub);
    font-size: 0.88rem;
    padding: 6px 4px 0;
}

.game-meta {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.back-link {
    color: #9ad9ff;
}

.back-link:hover {
    color: #ceefff;
}

@media (max-width: 980px) {
    .scanner-grid,
    .generator-grid {
        grid-template-columns: 1fr;
    }

    .preview-wrap,
    #camera,
    .camera-placeholder {
        min-height: 250px;
    }

    .btn-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .scanner-controls > button,
    .scanner-controls > .file-label {
        width: 100%;
    }

    .meta-footer {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100%, calc(100vw - 14px));
        margin: 10px auto calc(26px + env(safe-area-inset-bottom));
        gap: 12px;
    }

    .top-header {
        padding: 14px 12px;
    }

    .top-header h1 {
        font-size: clamp(1.45rem, 8vw, 2rem);
    }

    .top-header p {
        font-size: 0.88rem;
    }

    .panel {
        padding: 12px;
        border-radius: 12px;
    }

    .collection-list {
        grid-template-columns: 1fr;
    }

    .fighter-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    #battle-canvas {
        min-height: 210px;
    }

    .battle-panel {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .battle-winner-banner {
        min-width: calc(100% - 16px);
        bottom: 10px;
        gap: 8px;
        padding: 8px 10px;
    }

    #battle-winner-name {
        font-size: 0.9rem;
    }

    .winner-side {
        font-size: 0.68rem;
    }

    .mobile-controls {
        display: grid;
        position: sticky;
        bottom: max(8px, env(safe-area-inset-bottom));
        margin-top: 8px;
        padding: 8px;
        border-radius: 10px;
        background: rgba(4, 10, 20, 0.76);
        border: 1px solid rgba(122, 185, 228, 0.25);
        backdrop-filter: blur(3px);
    }

    .gesture-zone {
        min-height: 88px;
    }

    .controls-info {
        font-size: 0.84rem;
    }

    .meta-footer {
        font-size: 0.8rem;
        padding-top: 0;
    }
}

@media (max-width: 420px) {
    .preview-wrap,
    #camera,
    .camera-placeholder {
        min-height: 200px;
    }

    .panel h2 {
        font-size: 1rem;
    }

    .stat-list {
        grid-template-columns: 1fr;
    }

    .product-grid {
        grid-template-columns: 1fr;
    }

    .controls-info {
        font-size: 0.8rem;
    }

    .battle-sub-text {
        font-size: 0.72rem;
    }

    .mobile-controls {
        grid-template-columns: 1fr;
        grid-template-areas:
            'move'
            'action'
            'quick';
    }

    .mobile-quick-actions button {
        min-height: 46px;
        font-size: 0.9rem;
    }
}
