:root {
    color-scheme: light;
    --bg: #eef1ea;
    --panel: #ffffff;
    --panel-strong: #f7f8f3;
    --line: #c7cec1;
    --text: #20251f;
    --muted: #697064;
    --accent: #3d7458;
    --accent-dark: #2b5741;
    --focus: #d7872f;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background-color: var(--bg);
    background-image: url("images/bg-tile.png");
    background-repeat: repeat;
    color: var(--text);
    font-family: "Segoe UI", "Meiryo", sans-serif;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(640px, 1fr) 320px;
    gap: 16px;
    min-height: 100vh;
    padding: 16px;
}

.stage-panel,
.control-panel {
    border: 1px solid var(--line);
    background: var(--panel);
}

.stage-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stage-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 72px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-strong);
}

.stage-toolbar h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.35;
}

.stage-toolbar p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.status-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.status-group span {
    min-width: 96px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    background: #ffffff;
    text-align: center;
    font-size: 13px;
}

#previewCanvas {
    display: block;
    width: min(100%, 832px);
    height: auto;
    margin: auto;
    image-rendering: pixelated;
    background: #8bd8a0;
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
}

.control-section {
    display: grid;
    gap: 10px;
}

.control-section h2 {
    margin: 0;
    font-size: 15px;
    line-height: 1.4;
}

.field-label {
    color: var(--muted);
    font-size: 13px;
}

select,
.file-button {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--text);
}

select {
    padding: 0 10px;
}

.file-button {
    display: grid;
    place-items: center;
    cursor: pointer;
}

input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.drop-zone {
    display: grid;
    place-items: center;
    min-height: 112px;
    border: 2px dashed #8d9a89;
    background: #f5f7f2;
    color: var(--muted);
    font-size: 14px;
}

.drop-zone.is-active {
    border-color: var(--focus);
    background: #fff7e7;
    color: var(--text);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.pad-grid {
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 8px;
    justify-content: center;
}

.pad-grid button {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--text);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.pad-grid button:hover,
.pad-grid button:focus-visible,
.file-button:hover,
.file-button:focus-visible {
    border-color: var(--accent);
    outline: 2px solid transparent;
}

.pad-grid button:active {
    background: var(--accent);
    color: #ffffff;
}

.pad-grid button[data-direction="up"] {
    grid-column: 2;
    grid-row: 1;
}

.pad-grid button[data-direction="left"] {
    grid-column: 1;
    grid-row: 2;
}

.pad-grid button[data-direction="down"] {
    grid-column: 2;
    grid-row: 2;
}

.pad-grid button[data-direction="right"] {
    grid-column: 3;
    grid-row: 2;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .control-panel {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 8px;
    }

    .stage-toolbar,
    .control-panel {
        padding: 12px;
    }

    .stage-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .status-group {
        justify-content: flex-start;
    }

    .control-panel {
        grid-template-columns: 1fr;
    }
}
