:root {
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-soft: #eff6ff;
    --ink: #1e293b;
    --muted: #64748b;
    --line: #e2e8f0;
    --panel: #ffffff;
    --app-bg: #eef1f4;
    --header-h: 56px;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", "Helvetica Neue", Arial, sans-serif;
    background-color: var(--app-bg);
    color: var(--ink);
}

/* ヘッダー */
.app-header {
    height: var(--header-h);
    box-sizing: border-box;
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 0 20px;
    background: linear-gradient(90deg, #0f172a, #1e293b);
    color: #fff;
    line-height: var(--header-h);
    white-space: nowrap;
    overflow: hidden;
}

.app-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.app-sub {
    font-size: 12px;
    color: #94a3b8;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* 全体コンテナ */
.container {
    display: flex;
    width: 100vw;
    height: calc(100vh - var(--header-h));
}

.column {
    box-sizing: border-box;
}

/* 左カラム(操作パネル) */
.left-column {
    width: 320px;
    min-width: 320px;
    height: 100%;
    background-color: var(--panel);
    border-right: 1px solid var(--line);
    padding: 18px 18px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.left-column h3 {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.06em;
    margin: 0 0 14px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}

/* 右側(プレビュー) — 方眼紙風の背景 */
#sketch-holder {
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow: auto;
    background-color: var(--app-bg);
    background-image: radial-gradient(#c9d2dc 1px, transparent 1px);
    background-size: 22px 22px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 28px;
    box-sizing: border-box;
}

.right-column {
    width: 100%;
    max-width: 1600px;
}

#canvas-container {
    width: 100%;
}

/* p5.js-svg がラッパーdivにインラインで固定サイズを指定するため上書きする */
#canvas-container .p5Canvas {
    display: block !important;
    width: 100% !important;
    height: auto !important;
}

/* SVGは親幅にフィットさせ、縦横比を保つ(図面シート風) */
#canvas-container canvas,
#canvas-container svg {
    display: block;
    width: 100%;
    height: auto;
    background: #fff;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.08);
    border-radius: 8px;
}

/* コントロール */
.control-section {
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.control-group {
    position: relative;
    margin-bottom: 14px;
}

.control-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
    padding-right: 76px; /* 値チップと重ならないように */
}

/* 値はラベル行の右端にチップ表示 */
.control-group span {
    position: absolute;
    top: -1px;
    right: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid #dbeafe;
    padding: 1px 8px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.control-group input[type="number"],
.control-group select {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    color: var(--ink);
    background: #fff;
    outline: none;
}

.control-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

.control-group input[type="number"]:focus,
.control-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* スライダー */
.control-group input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    outline: none;
    margin: 6px 0 2px;
    cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
    transition: transform 0.1s;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}

.control-group input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--line);
}

/* ダウンロードボタン(サイドバー下部に固定) */
.download-btn {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    width: 100%;
    padding: 13px;
    background: linear-gradient(180deg, var(--accent), var(--accent-dark));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 0 0 6px var(--panel), 0 4px 12px rgba(37, 99, 235, 0.35);
    transition: transform 0.1s, box-shadow 0.1s;
}

.download-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
}

.download-btn:active {
    transform: translateY(0);
}

/* 狭い画面では上下に積む */
@media (max-width: 800px) {
    .app-header {
        padding: 0 14px;
    }
    .app-sub {
        display: none;
    }
    .container {
        flex-direction: column;
        height: auto;
    }
    .left-column {
        width: 100%;
        min-width: 0;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
    #sketch-holder {
        height: auto;
        padding: 14px;
    }
}
