:root {
    font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
    color: #14213d;
    background: #f6f4ef;
    font-size: 15px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

button,
input {
    font: inherit;
    color: inherit;
}

button {
    border: 2px solid #aab2c0;
    background: white;
    border-radius: 10px;
    min-height: 42px;
    padding: 6px 10px;
    cursor: pointer;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid #e85d04;
    outline-offset: 2px;
}


/* =========================
   アプリ全体
========================= */

.app {
    height: 100%;
    max-width: 1100px;
    margin: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

header {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
}

h1 {
    font-size: 18px;
    margin: 0;
}

.status {
    font-size: 12px;
    color: #586174;
}


/* =========================
   メインレイアウト
========================= */

.layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 250px;
    gap: 12px;
}


/* =========================
   キャンバスエリア
========================= */

.work {
    min-height: 0;
    display: grid;
    grid-template-columns: 68px minmax(0, 1fr);
    gap: 8px;
}

.canvas-area {
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.canvas-wrap {
    height: min(100%, calc(100vw - 320px));
    max-height: 100%;
    aspect-ratio: 1;
    max-width: 100%;
    width: auto;
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: white;
    border: 2px solid #14213d;
    touch-action: none;
    image-rendering: pixelated;
}

.stat {
    font-size: 12px;
    text-align: center;
    min-height: 1.5em;
}


/* =========================
   ツールバー
========================= */

.tools {
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: stretch;
}

.palette {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.swatch {
    width: 44px;
    min-height: 44px;
    padding: 0;
    border-color: #485267;
}

.swatch[aria-pressed="true"] {
    outline: 3px solid #e85d04;
    outline-offset: 1px;
}

.eraser {
    font-size: 11px;
}

.pen {
    font-size: 23px;
    min-height: 52px;
    padding: 2px;
}

.pen[aria-pressed="true"] {
    background: #ffead9;
    border-color: #e85d04;
}


/* =========================
   右側パネル
========================= */

.panel {
    background: #fff;
    border: 1px solid #d5d9e0;
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-height: 0;
    overflow: auto;
}

.panel h2 {
    font-size: 14px;
    margin: 0;
}

.panel button {
    width: 100%;
}


/* =========================
   聞くボタン
========================= */

.listen {
    font-weight: 900 !important;
    min-height: 88px !important;
    font-size: 25px !important;
    border: 3px solid #14213d !important;
}

.listen.on {
    background: #a31515;
    color: #fff;
}


/* =========================
   コマンド入力
========================= */

.command {
    display: flex;
    gap: 5px;
}

.command input {
    min-width: 0;
    width: 100%;
    border: 2px solid #aab2c0;
    border-radius: 8px;
    padding: 7px;
}

.command button {
    width: auto;
}


/* =========================
   チェック項目
========================= */

.checks {
    display: flex;
    gap: 8px;
    color: #166534;
    font-size: 13px;
    font-weight: 700;
}

.checks span {
    display: block;
}


/* =========================
   音声・センサー情報
========================= */

#heard,
#said,
#sensorStatus {
    font-size: 12px;
    line-height: 1.35;
    margin: 0;
    min-height: 1em;
    overflow-wrap: anywhere;
}


/* =========================
   ヘルプ
========================= */

.help {
    font-size: 11px;
    color: #586174;
    margin: 0;
}

.help summary {
    cursor: pointer;
}

.help p {
    margin: 4px 0;
}


/* =========================
   アクセシビリティ
========================= */

.hidden-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* =========================
   タブレット・スマホ
========================= */

@media (max-width: 650px) {

    body {
        height: 100dvh;
        overflow: hidden;
    }

    .app {
        height: 100%;
        min-height: 0;
        padding: 5px 7px;
        gap: 3px;
    }

    header {
        height: 29px;
    }

    h1 {
        font-size: 15px;
    }

    .status {
        font-size: 10px;
    }


    /* =====================
       メインレイアウト
    ===================== */

    .layout {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        gap: 5px;
    }


    /* =====================
       キャンバス
    ===================== */

    .work {
        display: flex;
        flex: 0 0 auto;
        flex-direction: column-reverse;
        gap: 3px;
    }

    .canvas-area {
        width: 100%;
    }

    /*
       キャンバスを画面横幅の90%にする
       vw = 画面の横幅
    */
    .canvas-wrap {
        width: 90vw;
        height: 90vw;
        max-width: 90vw;
        max-height: 90vw;
        aspect-ratio: 1;
    }


    /* =====================
       ツール
    ===================== */

    .tools {
        flex-direction: row;
        align-items: center;
        gap: 5px;
    }

    .palette {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .swatch {
        width: 37px;
        min-height: 37px;
    }

    .pen {
        min-height: 44px;
        font-size: 20px;
    }


    /* =====================
       パネル
    ===================== */

    .panel {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-content: start;
        overflow: auto;
        padding: 6px;
        gap: 4px;
    }

    .panel h2,
    .panel #listen,
    .panel #heard,
    .panel #said,
    .panel .command,
    .panel #shake,
    .panel #sensorStatus,
    .panel .checks {
        grid-column: 1 / -1;
    }

    .panel .help {
        display: none;
    }

    .panel button {
        min-height: 38px;
    }

    .panel #describe,
    .panel #clear {
        width: 100%;
    }


    /* =====================
       聞くボタン
    ===================== */

    .listen {
        min-height: 88px !important;
        font-size: 30px !important;
        width: 100%;
    }


    /* =====================
       全体のボタン
    ===================== */

    button {
        min-height: 38px;
        padding: 5px 7px;
        font-size: 13px;
    }
}


/* =========================
   小型スマホ
========================= */

@media (max-width: 370px) {

    .layout {
        grid-template-columns: minmax(0, 1fr) 128px;
    }

    .work {
        grid-template-columns: 39px minmax(0, 1fr);
    }

    .swatch {
        width: 34px;
        min-height: 34px;
    }

    .panel {
        padding: 5px;
    }

    .help {
        display: none;
    }
}


/* =========================
   横長・低い画面
========================= */

@media (max-height: 580px) and (min-width: 500px) {

    .app {
        padding: 4px 10px;
        gap: 3px;
    }

    header {
        height: 27px;
    }

    .panel {
        padding: 6px;
        gap: 4px;
    }

    .layout {
        grid-template-columns: minmax(0, 1fr) 225px;
    }

    .swatch {
        width: 38px;
        min-height: 38px;
    }
}
