﻿/* えもじデザイン v3 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Zen Maru Gothic', sans-serif;
    touch-action: manipulation;
    user-select: none;
}

body {
    background: linear-gradient(180deg, #FFF3E0 0%, #FFE0B2 100%);
}

#game-container.game-shell > .ui-chrome {
    padding-inline-end: max(4px, env(safe-area-inset-right, 0px));
}

#game-container.game-shell .ui-stats-row.emoji-stats {
    min-height: 30px;
}

.stat-pill {
    font-size: clamp(0.75rem, 3.2vmin, 0.88rem);
    font-weight: 800;
    color: #37474f;
    background: rgba(255, 255, 255, 0.95);
    padding: 5px 12px;
    border-radius: 999px;
    border: 2px solid #ffb74d;
}

/* ---- 全体レイアウト ---- */
.studio-screen {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 4px 6px;
    gap: 4px;
    overflow: hidden;
}

/* ---- キャンバス ---- */
.canvas-area {
    flex: 0 1 auto;
    min-height: 0;
    height: auto;
    max-height: min(28dvh, calc(var(--app-vh, 100dvh) * 0.28), 240px);
    aspect-ratio: 1;
    width: 100%;
    max-width: 100%;
    position: relative;
    background: #fefcf8;
    border-radius: 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    padding: 5px;
    box-sizing: border-box;
}

.emoji-stage {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    overflow: hidden;
    touch-action: none;
    background: #FFFDE7;
}

/* 削除FABボタン */
.delete-fab {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 200;
    padding: 7px 11px;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    border: none;
    border-radius: 10px;
    background: #ef5350;
    color: #fff;
    box-shadow: 0 3px 0 #b71c1c;
    cursor: pointer;
}

.delete-fab:active {
    transform: translateY(2px);
    box-shadow: none;
}

.delete-fab.hidden {
    display: none !important;
}

/* ---- はいけい（中央ぞろえ・見切れ防止） ---- */
.bg-row {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 2px 6px 4px;
    width: 100%;
    box-sizing: border-box;
}

.bg-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #5d4037;
    white-space: nowrap;
    text-align: center;
}

.bg-presets {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 4px 6px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

.bg-chip {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
}

.bg-chip[aria-pressed="true"] {
    border-color: #e65100;
    border-width: 2px;
    transform: scale(1.12);
}

/* ---- 絵文字パネル（4×4固定・スクロールなし） ---- */
.emoji-panel {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 16px;
    border: 2px solid #ffcc80;
}

/* タブバー */
.tab-bar {
    flex: 0 0 auto;
    display: flex;
    border-bottom: 2px solid #ffe0b2;
}

.tab-btn {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px 2px;
    font-size: clamp(1.05rem, 5vmin, 1.35rem);
    line-height: 1;
    border: none;
    background: transparent;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s;
}

.tab-btn.active {
    border-bottom-color: #e65100;
    background: #fff8e1;
}

/* 絵文字グリッド（横4列 × 縦4行 ＝ 16個） */
.emoji-grid {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 5px 4px 6px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.palette-item {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fffaf0;
    border-radius: 10px;
    border: 2px solid #ffe0b2;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
    font-family: inherit;
    transition: transform 0.1s;
    padding: 0;
}

.palette-item-emoji {
    font-size: clamp(0.95rem, min(5vmin, 7vw), 1.5rem);
    line-height: 1;
    display: block;
}

.palette-item:active {
    transform: scale(0.91);
}

/* ---- ステッカー ---- */
.emoji-sticker {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 52px;
    line-height: 1;
    cursor: grab;
    z-index: 1;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transform-origin: 50% 50%;
}

.emoji-sticker:active {
    cursor: grabbing;
}

/* 編集中：枠のみ */
.emoji-sticker.selected {
    z-index: 100;
    filter: none;
}

.emoji-sticker.selected::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    pointer-events: none;
    z-index: -1;
    border: 2px solid #e65100;
    border-radius: 6px;
    background: transparent;
}

/* ---- 削除アニメーション ---- */
@keyframes stickerPop {
    0% { transform: translate(-50%, -50%) scale(1.2); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

.emoji-sticker.just-added {
    animation: stickerPop 0.2s ease-out;
}

@media screen and (max-height: 640px) {
    .canvas-area {
        max-height: min(24dvh, calc(var(--app-vh, 100dvh) * 0.26), 200px);
        padding: 4px;
    }
    .bg-row { padding-bottom: 2px; }
    .emoji-grid { gap: 3px; padding: 4px 3px 5px; }
}
