:root {
    /* 背景色 */
    --bg-main: #494242;       /* メニューバー、情報バー */
    --bg-window: #5f5757;     /* ウィンドウ */
    --bg-dark: #2a2a2a;       /* 数値表示背景 */
    --bg-button: #4a4a4a;     /* ボタン基準 */
    --bg-panel: #f9f2de;    /* キャンバス背景 */
    --bg-status: #f0f0f0;

    --bg-button-hover: #d1a619; /* 選択前 */
    --box-shadow: rgb(153, 136, 122); /* 影 */

    /* テキスト */
    --text-white: white;
    --text-light: #ccc;

    /* ボーダー */
    --border-dark: #333;
    --border-medium: #555;
    --border-light: #666;
    --border-lighter: #888;

    /* アクセント */
    --accent-primary: #c0982a; /* 選択後 */
    --accent-hover: #e2b317;   /* 選択前 */
    --accent-gray: #945d29;    /* ボタン囲い */
    --accent-handle: #c4863f5e;/* スライダーハンドル */
}

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

body {
    font-family: 'メイリオ', 'Meiryo', sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    background: var(--bg-main);
}

/* メニューバー */
#menu-bar {
    background: var(--bg-main);
    padding: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    box-shadow: 0 0 0cap 4px var(--box-shadow);
    position: relative;
    z-index: 120;
    height: 64px;
    flex-shrink: 0;
}

.chevron-button {
    position: relative;
    background: var(--bg-main);
    color: var(--text-white);
    border: none;
    padding: 15px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    touch-action: manipulation;
    font-family: 'Material Symbols Outlined';
    font-size: 32px;
    line-height: 1;
    font-weight: normal;
    font-style: normal;
    display: inline-block;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    box-shadow: inset 0 -1px 3px var(--box-shadow);
}

@media (hover: hover) {
    .chevron-button:hover:not(.active) {
        background: var(--bg-button-hover);
    }
    .menu-toggle:hover {
        background: #a0a0a0;
    }
}

.icon {
    font-family: 'Material Symbols Outlined';
    font-size: 32px;
}

/* レスポンシブメニュー（700px以下でも1行で6アイコン全表示） */
@media (max-width: 700px) {
    .chevron-button, .menu-toggle {
        display: flex;
        flex: 1;
        padding: 12px 4px;
        justify-content: center;
        align-items: center;
    }
}

/* 情報バー（サイズ%） */
#info-bar {
    background: var(--bg-main);
    color: var(--text-white);
    display: flex;
    align-items: center;
    padding: 8px 14px;
    box-shadow: inset 0 -1px 2px var(--box-shadow), 0 0 0px 4px var(--box-shadow);
    z-index: 100;
    font-family: 'Inter', sans-serif;
    flex-shrink: 0;
}

.pd-display {
    padding: 0px 6px;
    font-size: 24px;
    font-weight: bold;
}

/* SIZEコントロール（枠なし数字＋押しやすい外出しボタン＋小数点表示対応） */
.size-control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.size-label {
    font-size: 22px;
    font-weight: bold;
    margin-right: 4px;
}

.size-number-input {
    width: 86px;
    padding: 2px 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-white);
    font-size: 26px;
    font-weight: bold;
    text-align: right;
    font-family: 'Inter', monospace, sans-serif;
    -moz-appearance: textfield;
    appearance: textfield;
}

.size-number-input::-webkit-outer-spin-button,
.size-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.size-unit {
    font-size: 18px;
    font-weight: bold;
    margin-right: 4px;
}

.size-step-btn {
    width: 42px;
    height: 42px;
    background: var(--bg-button);
    color: var(--text-white);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: background 0.15s, transform 0.1s;
}

@media (hover: hover) {
    .size-step-btn:hover {
        background: var(--bg-button-hover);
        border-color: var(--accent-gray);
    }
}

.size-step-btn:active {
    background: var(--accent-primary);
    transform: scale(0.95);
}

/* メインコンテナ（PC：左端パネル＋右側キャンバス） */
#main-container {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-panel);
    overflow: hidden;
    position: relative;
}

#main-canvas {
    cursor: move;
    max-width: 100%;
    max-height: 100%;
}

#status-bar {
    background-color: var(--bg-status);
    border-top: 1px solid var(--text-light);
    padding: 5px 10px;
    font-size: 12px;
    flex-shrink: 0;
}

/* 左端固定サイドパネル共通（PCでは左端固定・縦スクロール） */
.side-panel {
    width: 260px;
    flex-shrink: 0;
    height: 100%;
    background: var(--bg-window);
    border-right: 2px solid var(--border-medium);
    box-shadow: 2px 0 8px var(--box-shadow);
    z-index: 90;
    display: none;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}

.side-panel.show {
    display: flex;
}

.window-header {
    background: var(--bg-main);
    color: var(--text-white);
    padding: 0;
    display: flex;
    align-items: stretch;
    user-select: none;
    border-bottom: 2px solid var(--border-light);
    position: relative;
    z-index: 5;
    flex-shrink: 0;
}

.window-drag-bar {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: default;
    user-select: none;
}

.window-title {
    flex: 1;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.window-title .icon {
    font-size: 28px;
    font-family: 'Material Symbols Outlined';
}

.close-btn {
    background: var(--bg-main);
    border: none;
    color: var(--text-white);
    cursor: pointer;
    width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    border-radius: 0;
    position: relative;
    z-index: 10;
}

.close-btn .icon {
    font-family: 'Material Symbols Outlined';
    font-size: 24px;
}

.close-btn:hover {
    background: #d55550;
}

.window-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--bg-window);
    color: var(--text-white);
}

/* フレーム選択リスト（PC：左端1列表示） */
.frame-grid {
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg-window);
}

.frame-item {
    background: var(--bg-window);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    border-bottom: 1px solid #333;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.frame-item:hover {
    background: var(--bg-button-hover);
}

.frame-item.selected {
    background: var(--bg-button);
    box-shadow: inset 0 0 0px 3px var(--accent-gray);
}

.frame-item img {
    width: 100%;
    aspect-ratio: 8 / 3;
    object-fit: contain;
    background: var(--text-white);
    border-radius: 3px;
}

.frame-item-name {
    color: var(--text-white);
    font-size: 13px;
    margin-top: 6px;
    text-align: center;
    line-height: 1.2;
    word-break: break-all;
}

/* 生地選択リスト（PC：左端1列表示） */
.texture-grid {
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg-window);
}

.texture-item {
    background: var(--bg-window);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    border-bottom: 1px solid #333;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
}

.texture-item:hover {
    background: var(--bg-button-hover);
}

.texture-item.selected {
    background: var(--bg-button);
    box-shadow: inset 0 0 0px 3px var(--accent-gray);
}

.texture-preview {
    width: 100%;
    aspect-ratio: 8 / 3;
    border-radius: 2px;
    background-size: cover;
    background-position: center;
    border: none;
}

.texture-item-icon {
    font-family: 'Material Symbols Outlined';
    font-size: 32px;
}

.texture-item-name {
    color: var(--text-white);
    font-size: 14px;
    margin-top: 6px;
    text-align: center;
    line-height: 1.2;
}

/* カラーウィンドウ */
#color-window .window-body {
    padding: 16px;
}

#color-window .color-picker-area {
    height: 200px;
}

/* タブスタイル */
.tab-header {
    display: flex;
    border-bottom: 2px solid var(--border-medium);
    flex-shrink: 0;
}

.tab-button {
    flex: 1;
    background: var(--bg-dark);
    color: var(--bg-button);
    border: none;
    padding: 6px 16px;
    cursor: pointer;
    font-size: 30px;
    font-weight: 500;
    transition: all 0.2s;
    border-right: 1px solid var(--border-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab-button:last-child {
    border-right: none;
}

.tab-button:hover {
    background: var(--bg-button-hover);
    color: var(--text-white);
}

.tab-button.active {
    background: var(--bg-window);
    color: var(--text-white);
}

.tab-button .icon {
    font-size: 30px;
    font-family: 'Material Symbols Outlined';
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 2Dカラーピッカー */
.color-picker-area {
    width: 100%;
    height: 200px;
    position: relative;
    cursor: crosshair;
    border-radius: 0px;
    margin-bottom: 16px;
    background: linear-gradient(to bottom, transparent, black),
                linear-gradient(to right, var(--text-white), transparent);
}

.color-picker-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid var(--text-white);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--box-shadow);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 10;
}

/* カラースライダー */
.color-slider {
    margin-bottom: 16px;
}

.slider-track {
    width: 100%;
    height: 12px;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
}

.hue-track {
    background: linear-gradient(to right,
        rgb(255,0,0) 0%,
        rgb(255,255,0) 17%,
        rgb(0,255,0) 33%,
        rgb(0,255,255) 50%,
        rgb(0,0,255) 67%,
        rgb(255,0,255) 83%,
        rgb(255,0,0) 100%
    );
}

.opacity-track {
    background: linear-gradient(to right, transparent, #fff),
                repeating-linear-gradient(45deg, #ccc 0px, #ccc 10px, #fff 10px, #fff 20px);
}

.slider-handle {
    position: absolute;
    top: 50%;
    width: 20px;
    height: 20px;
    background: var(--accent-handle);
    border: 2px solid var(--box-shadow);
    border-radius: 4px;
    transform: translate(-50%, -50%);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--box-shadow);
}

/* RGBA表示 */
#color-window .rgba-display {
    padding: 4px;
    gap: 0px;
    display: flex;
    background: var(--bg-dark);
    border-radius: 3px;
}

#color-window .rgba-label {
    font-size: 14px;
    color: var(--text-white);
    margin-bottom: 0px;
}

#color-window .rgba-value {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-white);
}

.rgba-item {
    flex: 1;
    text-align: center;
}

.loading {
    color: var(--text-light);
    text-align: center;
    font-style: italic;
    padding: 16px;
}

/* ===================================================
   スマホ画面（700px以下）：
   ・キャンバスを上寄せ配置
   ・ウィンドウを下部固定
   ・フレーム選択＆テクスチャ選択は横スクロール1行表示
   ・カラー設定は下部でコンパクトに収まるレイアウト
=================================================== */
@media (max-width: 700px) {
    #main-container {
        flex-direction: column;
    }

    /* キャンバスを上に配置（order: 1）、パネルを下に配置（order: 2） */
    #canvas-container {
        order: 1;
        align-items: flex-start;
    }

    .side-panel {
        order: 2;
        width: 100%;
        height: auto;
        border-right: none;
        border-top: 2px solid var(--border-medium);
        box-shadow: 0 -2px 8px var(--box-shadow);
    }

    .window-drag-bar {
        padding: 6px 12px;
    }

    .window-title {
        font-size: 14px;
    }

    .window-title .icon {
        font-size: 22px;
    }

    .close-btn {
        width: 42px;
    }

    /* フレーム・生地選択：スマホ下部の横スクロールカルーセル */
    #frame-window .window-body,
    #texture-window .window-body {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .frame-grid,
    .texture-grid {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: stretch;
        width: max-content;
        min-width: 100%;
    }

    .frame-item,
    .texture-item {
        width: 160px;
        flex-shrink: 0;
        border-bottom: none;
        border-right: 1px solid #333;
        padding: 8px;
    }

    /* カラー設定：スマホ下部に収まるコンパクトレイアウト */
    #color-window .window-body {
        padding: 10px 14px;
        max-height: 42dvh;
        overflow-y: auto;
    }

    #color-window .color-picker-area {
        height: 120px;
        margin-bottom: 12px;
    }

    #color-window .color-slider {
        margin-bottom: 12px;
    }

    .tab-button {
        padding: 4px 12px;
        font-size: 24px;
    }

    .tab-button .icon {
        font-size: 24px;
    }
}
