
* { box-sizing: border-box; }
body {
    font-family: sans-serif;
    background: #c0c0c0;
    margin: 0;
    padding: 10px;
    user-select: none;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#main-area {
    display: flex;
    flex: 1;
    gap: 10px;
    min-height: 0;
}

#toolbar {
    width: 120px;
    background: #d4d0c8;
    border: 4px outset #ffffff;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 40px;
    gap: 4px;
}

button.tool-btn {
    padding: 0;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    border: 4px outset #ffffff;
    background: #d4d0c8;
    display: flex;
    align-items: center;
    justify-content: center;
}
button.tool-btn:active, button.tool-btn.active {
    border-style: inset;
    background: #e0e0e0;
}

.option-container {
    border: 2px inset #ffffff;
    background: #e0e0e0;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 170px;
}

.panel-title {
    font-size: 11px;
    font-weight: bold;
    color: #444;
    text-align: center;
}

.option-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.brush-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
}

.aa-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid #b0b0b0;
}

.eraser-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.fill-grid, .filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}

.option-btn {
    height: 30px;
    border: 2px outset #ffffff;
    background: #d4d0c8;
    font-size: 10px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.option-btn.active {
    border-style: inset;
    background: #ffffff;
}

.rect-style-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
}
.rect-style-btn {
    height: 24px;
    border: 2px outset #ffffff;
    background: #d4d0c8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.rect-style-btn.active {
    border-style: inset;
    background: #ffffff;
}
.rect-icon {
    width: 20px;
    height: 14px;
    border: 1px solid #000;
    box-sizing: border-box;
}
.rect-icon.fill-bg { background-color: #808080; }
.rect-icon.fill-fg { background-color: #000000; border-color: #000; }

.circle-icon {
    width: 18px;
    height: 14px;
    border: 1px solid #000;
    border-radius: 50%;
    box-sizing: border-box;
}
.circle-icon.fill-bg { background-color: #808080; }
.circle-icon.fill-fg { background-color: #000000; border-color: #000; }

.toolbar-footer {
    margin-top: auto;
}

#canvas-container {
    position: relative;
    flex: 1;
    background: #808080;
    border: 4px inset #ffffff;
    overflow: auto;
}

#zoom-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
#bgCanvas { background: transparent; }

/* キャンバス用チェッカー柄（ライト） */
#bgCanvas.checkerboard-bg {
    background-color: #ffffff;
    background-image: 
        linear-gradient(45deg, #ccc 25%, transparent 25%), 
        linear-gradient(-45deg, #ccc 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #ccc 75%), 
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

/* キャンバス用チェッカー柄（ダーク） */
#bgCanvas.checkerboard-dark-bg {
    background-color: #333333;
    background-image: 
        linear-gradient(45deg, #555 25%, transparent 25%), 
        linear-gradient(-45deg, #555 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #555 75%), 
        linear-gradient(-45deg, transparent 75%, #555 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

#onion-canvas { pointer-events: none; opacity: 0.5; }
#overlay-canvas { pointer-events: none; }

#bottom-bar {
    height: 96px;
    margin-top: 10px;
    background: #d4d0c8;
    border: 4px outset #ffffff;
    display: flex;
    align-items: center;
    padding: 8px;
    gap: 16px;
}

#color-preview {
    position: relative;
    width: 64px;
    height: 64px;
    border: 4px inset #ffffff;
    background: #c0c0c0;
    flex-shrink: 0;
    cursor: pointer;
}
#color-preview:active {
    border-style: outset;
}
#bg-color-box {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 36px;
    height: 36px;
    border: 2px solid #000;
    background-color: #ffffff;
    pointer-events: none;
}
#fg-color-box {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 36px;
    height: 36px;
    border: 2px solid #000;
    background-color: #000000;
    z-index: 1;
    pointer-events: none;
}

#palette {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-auto-flow: column;
    gap: 2px;
    height: 68px;
    background: #808080;
    border: 2px inset #ffffff;
    padding: 2px;
}
.color-swatch {
    width: 30px;
    height: 30px;
    border: 2px solid #808080;
    cursor: pointer;
}
.color-swatch:hover {
    border-color: #000;
}

.palette-edit-btn {
    height: 68px;
    width: 36px;
    border: 2px outset #ffffff;
    background: #d4d0c8;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    text-align: center;
    line-height: 1.2;
}
.palette-edit-btn:active, .palette-edit-btn.active {
    border-style: inset;
    background: #e0e0e0;
}

#status-area {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    padding-right: 8px;
}

.status-box {
    background: #e0e0e0;
    border: 2px inset #ffffff;
    padding: 4px 8px;
    min-width: 80px;
    text-align: center;
    min-height: 27px;
}

#size-label, #zoom-label {
    cursor: pointer;
}
#size-label:hover, #zoom-label:hover {
    background: #ffffff;
}

.layer-control-container, .frame-control-container {
    display: flex;
    align-items: center;
}
.layer-boxes, .frame-boxes {
    display: flex;
    gap: 4px;
    border: 2px inset #ffffff;
    background: #808080;
    padding: 3px;
}
.layer-box, .frame-btn {
    height: 32px;
    padding: 0 6px;
    border: 2px outset #ffffff;
    background: #d4d0c8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    position: relative;
    box-sizing: border-box;
    white-space: nowrap;
}
.layer-box.active, .frame-btn.active {
    border-style: inset;
    background: #e0e0e0;
}
.layer-box.hidden {
    opacity: 0.5;
    background: #a0a0a0;
    text-decoration: line-through;
}
.layer-box.active {
    border: 2px solid #000080;
    outline: 2px solid #ff0000;
    z-index: 2;
}
.frame-label {
    min-width: 60px;
    height: 32px;
    background: #e0e0e0;
    border: 2px inset #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}
#frame-display-label {
    cursor: pointer;
}
#frame-display-label:hover {
    background: #ffffff;
}
.modal-row select, .modal-row input[type="color"] {
    width: 120px;
    padding: 2px 4px;
    border: 2px inset #ffffff;
}
.layer-box-bg {
    background: #ffffff;
    font-size: 10px;
}
.layer-box-bg.transparent {
    background-color: #ffffff;
    background-image: 
        linear-gradient(45deg, #ccc 25%, transparent 25%), 
        linear-gradient(-45deg, #ccc 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #ccc 75%), 
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}
.layer-box-bg.dark-transparent {
    background-color: #333333;
    background-image: 
        linear-gradient(45deg, #555 25%, transparent 25%), 
        linear-gradient(-45deg, #555 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #555 75%), 
        linear-gradient(-45deg, transparent 75%, #555 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-dialog {
    background: #d4d0c8;
    border: 4px outset #ffffff;
    padding: 16px;
    width: 320px;
    box-shadow: 4px 4px 10px rgba(0,0,0,0.3);
}
.modal-title {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 12px;
    border-bottom: 2px groove #ffffff;
    padding-bottom: 4px;
}
.modal-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
    font-size: 13px;
}
.modal-row label { width: 60px; }
.modal-row input[type="number"] {
    width: 90px;
    padding: 2px 4px;
    border: 2px inset #ffffff;
}
.anchor-grid {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(3, 36px);
    gap: 4px;
    background: #808080;
    padding: 4px;
    border: 2px inset #ffffff;
    width: max-content;
    margin: 0 auto 12px auto;
}
.anchor-btn {
    border: 2px outset #ffffff;
    background: #d4d0c8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}
.anchor-btn.active {
    border-style: inset;
    background: #000080;
    color: #ffffff;
}
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.modal-btn {
    padding: 4px 16px;
    border: 2px outset #ffffff;
    background: #d4d0c8;
    font-weight: bold;
    cursor: pointer;
}
.modal-btn:active { border-style: inset; }