/* =========================================
   Portopia layout
   ステータス10% / 背景40% / コメント25% / 選択肢30%
   ========================================= */
:root {
    --fc-bg: #000000;
    --fc-panel: #000088;
    --fc-border: #fcfcfc;
    --fc-border2: #7878f8;
    --fc-white: #fcfcfc;
    --fc-yellow: #f8b800;
    --fc-red: #e83800;
    --fc-gray: #888888;
    --fc-cyan: #00e8d8;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --vvh: 100dvh;
}

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

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

html {
    width: 100%;
    height: 100%;
    height: -webkit-fill-available;
    background: var(--fc-bg);
}

body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    position: fixed;
    inset: 0;
    overscroll-behavior: none;
    background: var(--fc-bg);
    font-family: 'DotGothic16', monospace;
    color: var(--fc-white);
    image-rendering: pixelated;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding:
        max(4px, var(--safe-t))
        max(6px, var(--safe-r))
        max(6px, var(--safe-b))
        max(6px, var(--safe-l));
}

.scanline {
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.18) 2px,
        rgba(0, 0, 0, 0.18) 4px
    );
    box-shadow: inset 0 0 48px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 50;
}

.screen-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    opacity: 0;
}
.flash-white { animation: flashWhite 0.15s steps(2); }
.flash-red { animation: flashRed 0.35s steps(3); }

@keyframes flashWhite {
    0% { background: rgba(252, 252, 252, 0.85); opacity: 1; }
    100% { background: rgba(252, 252, 252, 0); opacity: 0; }
}
@keyframes flashRed {
    0% { background: rgba(232, 56, 0, 0.7); opacity: 1; }
    100% { background: rgba(232, 56, 0, 0); opacity: 0; }
}

.game-container {
    width: 100%;
    max-width: 430px;
    height: calc(var(--vvh) - var(--safe-t) - var(--safe-b) - 8px);
    max-height: calc(var(--vvh) - var(--safe-t) - var(--safe-b) - 8px);
    background: var(--fc-bg);
    border: 3px solid var(--fc-border2);
    padding: 4px 6px 6px;
    position: relative;
    z-index: 100;
    display: grid;
    /* ステータス10 / 背景40 / コメント20(=旧25の80%) / 選択肢30 */
    grid-template-rows: 10% 40% 20% 30%;
    gap: 0;
    overflow: hidden;
    box-shadow: 4px 4px 0 #000;
}

.shake-anim {
    animation: shake 0.35s steps(4) both;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-4px); }
}

/* --- 10% ステータス --- */
.header {
    grid-row: 1;
    text-align: center;
    border-bottom: 2px solid var(--fc-border);
    padding: 2px 0 4px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    overflow: hidden;
}
.header h1 {
    font-size: clamp(10px, 2.8vw, 13px);
    color: var(--fc-yellow);
    letter-spacing: 1px;
    text-shadow: 2px 2px 0 #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.stats-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.stat-box,
.audio-btn {
    background: var(--fc-panel);
    color: var(--fc-white);
    border: 2px solid var(--fc-border);
    box-shadow: 2px 2px 0 #000;
    padding: 2px 8px;
    font-family: inherit;
    font-size: clamp(10px, 2.6vw, 12px);
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.stat-label {
    color: var(--fc-cyan);
}
.item-btn {
    cursor: pointer;
    touch-action: manipulation;
}
.item-btn:active,
.item-btn.is-pressed,
.audio-btn:active,
.audio-btn.is-pressed {
    transform: translate(2px, 2px) scale(0.94);
    box-shadow: 0 0 0 #000;
    filter: brightness(1.25);
}
.audio-btn {
    cursor: pointer;
    color: var(--fc-gray);
    border-color: var(--fc-gray);
    background: #000;
    touch-action: manipulation;
    flex-shrink: 0;
}
.audio-btn.active {
    color: var(--fc-yellow);
    border-color: var(--fc-yellow);
}

.progress-bar {
    height: 4px;
    border: 1px solid var(--fc-border);
    padding: 0;
    width: 100%;
    flex-shrink: 0;
}
.progress-fill {
    height: 100%;
    background: var(--fc-red);
    width: 0%;
    transition: width 0.25s steps(6);
}

/* --- 40% 背景（枠いっぱい） --- */
.scene-view {
    grid-row: 2;
    background: #000;
    border: 3px solid var(--fc-border);
    border-bottom: none;
    min-height: 0;
    display: block;
    overflow: hidden;
    line-height: 0;
    position: relative;
}
.scene-view canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* --- 20% コメント（旧25%の80%） --- */
.message-window {
    grid-row: 3;
    position: relative;
    min-height: 0;
    padding: 4px 8px 8px;
    background: #000028;
    border: 3px solid var(--fc-border);
    border-top: 2px solid var(--fc-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.location-label {
    display: inline-block;
    background: var(--fc-white);
    color: #000;
    padding: 1px 6px;
    font-size: clamp(9px, 2.2vw, 11px);
    letter-spacing: 1px;
    margin-bottom: 3px;
    box-shadow: 2px 2px 0 #5050a0;
    flex-shrink: 0;
    align-self: flex-start;
}
.story-text {
    line-height: 1.4;
    font-size: clamp(11px, 3vw, 13px);
    color: var(--fc-white);
    white-space: pre-wrap;
    letter-spacing: 0.5px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.message-window::after {
    content: '▼';
    position: absolute;
    bottom: 2px;
    right: 6px;
    font-size: 9px;
    color: var(--fc-yellow);
    animation: fc-blink 0.8s step-end infinite;
}
@keyframes fc-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* --- 30% 選択肢：3枠がちょうど収まる --- */
.choices-container {
    grid-row: 4;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 0;
    padding: 3px 0 0;
    overflow: hidden;
    touch-action: manipulation;
    position: relative;
    z-index: 5;
}

.choice-btn {
    background: #000;
    color: var(--fc-white);
    border: 2px solid var(--fc-border);
    padding: 0 10px;
    font-family: inherit;
    font-size: clamp(11px, 3.2vw, 14px);
    letter-spacing: 1px;
    cursor: pointer;
    text-align: left;
    box-shadow: 2px 2px 0 #303070;
    flex: 1 1 0;
    min-height: 44px;
    height: auto;
    max-height: none;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    touch-action: manipulation;
    position: relative;
    z-index: 6;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.05s ease, filter 0.05s ease, border-color 0.05s ease;
}

.choice-btn:active,
.choice-btn.is-pressed {
    transform: none;
    box-shadow: 2px 2px 0 #303070;
    background: var(--fc-panel);
    color: var(--fc-yellow);
    border-color: var(--fc-yellow);
    filter: brightness(1.35);
}

.treasure-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 300;
    pointer-events: none;
    transition: transform 0.15s steps(3);
}
.treasure-popup.show {
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}
.popup-border {
    background: #000;
    border: 3px solid var(--fc-border);
    padding: 14px 16px;
    text-align: center;
    box-shadow: 6px 6px 0 #000;
    width: 220px;
}
.treasure-icon {
    font-size: 18px;
    color: var(--fc-cyan);
    margin-bottom: 4px;
}
.treasure-text {
    color: var(--fc-yellow);
    font-size: 12px;
    letter-spacing: 1px;
    text-shadow: 2px 2px 0 #880000;
}

/* タイトル画面の特別スタイル */
.game-container.is-title-screen {
    grid-template-rows: 25% 40% 0% 35%;
}

.game-container.is-title-screen .header {
    padding: 8px 0 12px;
    border-bottom: 3px solid var(--fc-yellow);
    background: linear-gradient(180deg, rgba(248, 184, 0, 0.1) 0%, transparent 100%);
    box-shadow: inset 0 0 12px rgba(248, 184, 0, 0.08);
}

.game-container.is-title-screen .header h1 {
    font-size: clamp(18px, 5.5vw, 24px);
    color: var(--fc-yellow);
    text-shadow: 3px 3px 0 #000, -1px -1px 0 var(--fc-cyan);
    letter-spacing: 2px;
    line-height: 1.3;
    animation: title-pulse 1.2s ease-in-out infinite;
}

@keyframes title-pulse {
    0%, 100% { text-shadow: 3px 3px 0 #000, -1px -1px 0 var(--fc-cyan); }
    50% { text-shadow: 4px 4px 0 #000, -2px -2px 0 var(--fc-cyan), 0 0 8px rgba(248, 184, 0, 0.6); }
}

.game-container.is-title-screen .stats-row {
    opacity: 0.6;
}

.game-container.is-title-screen .message-window {
    display: none;
}

.game-container.is-title-screen .choices-container {
    padding: 6px 0 0;
}

.game-container.is-title-screen .choice-btn:first-child {
    background: var(--fc-panel);
    border-color: var(--fc-yellow);
    color: var(--fc-yellow);
    box-shadow: 3px 3px 0 #000, inset 0 0 8px rgba(248, 184, 0, 0.2);
    font-size: clamp(13px, 3.8vw, 16px);
    min-height: 52px;
}

.game-container.is-title-screen .choice-btn:first-child:active,
.game-container.is-title-screen .choice-btn:first-child.is-pressed {
    background: var(--fc-yellow);
    color: #000;
    filter: brightness(1.1);
}

@media (max-height: 560px) {
    .header h1 {
        font-size: 10px;
    }
    .stat-box,
    .audio-btn {
        min-height: 24px;
        font-size: 10px;
        padding: 1px 6px;
    }
    .game-container.is-title-screen {
        grid-template-rows: 20% 40% 0% 40%;
    }
}
