:root {
   
    --dvh: 1vh;

   
   
    --button-size: clamp(34px, calc((100 * var(--dvh) - 64px) / 14), 52px);
    --palette-button-width: clamp(52px, 5vw, 72px);
   
    --h-describe: clamp(64px, calc(11 * var(--dvh)), 96px);
    --h-usage: clamp(52px, calc(8.5 * var(--dvh)), 76px);
    --h-sub: clamp(44px, calc(6 * var(--dvh)), 52px);
    --fs-describe: clamp(20px, 2vw, 26px);
    --fs-usage: clamp(17px, 1.6vw, 21px);

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

html,
body {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

@supports (height: 1dvh) {
    :root {
        --dvh: 1dvh;
    }
}

body {
    margin: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

.audio-unlock-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #000000b2;
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    color: #fff;
    transition: opacity .2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: default;
}

.audio-unlock-prompt {
    width: min(100%, 520px);
    min-height: 120px;
    padding: 24px;
    border: none;
    border-radius: 18px;
    color: #ffffff;
    background: #ffffff00;
    font-size: clamp(24px, 6vw, 42px);
    font-weight: 900;
    text-align: center;
    display: grid;
    place-items: center;
}

.audio-unlock-overlay.is-hidden {
    opacity: 0;
    pointer-events: none;
}

button,
input {
    font: inherit;
    color: inherit;
    user-select: none;
    -webkit-user-select: none;
}

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

summary {
    cursor: default;
}

button.tap-pending {
    border-color: #04b3e8 !important;
    box-shadow: 0 0 0 3px rgba(4, 133, 232, 0.35);
    filter: brightness(1.12);
}

button.voiceover-target,
[role="button"].voiceover-target,
summary.voiceover-target {
    outline: 4px solid #d40000;
    outline-offset: 3px;
    filter: brightness(1.12);
}

button.voiceover-active,
[role="button"].voiceover-active,
summary.voiceover-active {
    background: #ffe2e2 !important;
    transform: scale(.96);
}

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




.app {
    height: 100%;
    max-width: 1100px;
    margin: auto;
    padding: 4px 8px;
    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) 220px;
    gap: 12px;
}




.work {
    min-height: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
    width: 100%;
    flex: 1;
}


@media (min-width: 901px), (orientation: landscape) and (min-width: 651px) {
    .app {
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }

    .work {
        padding-left: 126px;
    }

   
    .panel {
        padding-bottom: calc(var(--corner-height, clamp(110px, 25vh, 220px)) + 8px);
    }
}

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

.canvas-wrap {
    position: relative;
    width: min(100%, calc(100vw - 430px), calc(100 * var(--dvh) - 40px));
    height: auto;
    aspect-ratio: 1 / 1;
    flex: none;
}

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

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




.tools {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
    justify-content: center;
}

.palette {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}

.palette-row {
    display: contents;
}

.palette .swatch {
    grid-column: 1;
}

.palette .pen,
.palette #undo {
    grid-column: 1;
}

.palette .pen {
    grid-column: 1;
    grid-row: 13;
}

.palette #undo {
    grid-column: 1;
    grid-row: 14;
}

.swatch {
    width: var(--palette-button-width);
    height: var(--button-size);
    min-width: var(--palette-button-width);
    min-height: var(--button-size);
    padding: 0;
    border-color: #485267;
    font-weight: 900;
}

.palette-row > .pen,
.palette-row > #undo {
    width: var(--palette-button-width);
    height: var(--button-size);
    min-width: var(--palette-button-width);
    min-height: var(--button-size);
    padding: 2px;
}

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

.eraser {
    font-size: 11px;
}

.pen,
.palette #undo {
    font-size: 24px;
}

.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: hidden;
    min-width: 0;
    overflow-wrap: anywhere;
}

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

.panel button {
    width: 100%;
}
.panel-qr button {
    width: 100%;
}
#startCamera{
    background: #aaffab;
    border: 2px solid #0f6d00;
}
#stopCamera{
    background: #ffbaba;
    border: 2px solid #6d0000;
}

.voice-actions {
    display: flex;
    gap: 7px;
    width: 100%;
    grid-column: 1 / -1;
}

.voice-actions > button {
    flex: 1 1 0;
    min-width: 0;
}

.clear-actions {
    display: flex;
    width: 100%;
    gap: 7px;
}

.clear-actions > button {
    flex: 1 1 0;
    min-width: 0;
}
#clear{
    width: 100%;
    background: #d5ffd6;
    border: 2px solid #0f6d00;
    color: #000000;
    font-weight: 900 !important;
}
#clear:active{
    background: #149500;
    color: #fff;
}



.panel button {
    min-height: var(--h-sub);
    font-size: 16px;
}

.voice-actions #describe {
    min-height: var(--h-describe);
    font-size: var(--fs-describe);
}


.panel button:is(.usage-button, [id*="usage" i], [id*="guide" i], [id*="howto" i], [id*="tutorial" i], [id*="manual" i], [aria-label*="使い方"], [title*="使い方"]) {
    min-height: var(--h-usage);
    font-size: var(--fs-usage);
    font-weight: 900;
    color: #000;
    background: #fff1c9;
    border: 3px solid #7a4b00;
}


.clear-actions {
    flex-wrap: wrap;
}

.clear-actions > button {
    flex: 1 1 150px;
}

.clear-actions > button:is(.usage-button, [id*="usage" i], [id*="guide" i], [id*="howto" i], [id*="tutorial" i], [id*="manual" i], [aria-label*="使い方"], [title*="使い方"]) {
    flex: 2 1 150px;
    order: -1;
}


#heard,
#said {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#heard {
    -webkit-line-clamp: 3;
}

#said {
    -webkit-line-clamp: 4;
}

#sensorStatus:empty {
    min-height: 0;
}


.listen {
    font-weight: 900 !important;
    min-height: 88px !important;
    font-size: 22px !important;
    border: 3px solid #7c0000 !important;
    background: #ffd5d5;
    transition: background 0.1s, color 0.1s;
}
.voice-actions #describe {
    background: #cdddff;
    font-weight: 900 !important;
    color: #000;
    border: 3px solid #00296f !important;
    transition: background 0.1s, color 0.1s;
}

.listen.on{
    background: #ff0000;
    color: #fff;
}
.voice-actions #describe.on{
    background: #005eff;
    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;
}

#said {
    min-height: 2.7em;
}




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

.help summary {
    cursor: default;
}

.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;
}

.share-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.share-dialog {
    width: min(560px, calc(100vw - 24px));
    max-width: none;
    padding: 16px;
    border: 2px solid #485267;
    border-radius: 14px;
    color: #14213d;
    text-align: center;
}

.share-dialog::backdrop {
    background: rgb(20 33 61 / 65%);
}

.share-dialog h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.share-dialog p {
    margin: 8px 0;
}

.share-dialog img {
    display: block;
    width: min(88vw, 480px);
    height: auto;
    margin: 10px auto;
    image-rendering: pixelated;
}

.share-dialog button {
    width: auto;
    min-width: 120px;
}

.readonly-page {
    background: #e7f4e9;
}

.readonly-page .panel {
    background: #f4fbf5;
    border-color: #87b892;
}

.readonly-page .canvas-wrap canvas {
    border-color: #28743a;
}

.readonly-badge {
    padding: 5px 10px;
    border: 1px solid #28743a;
    border-radius: 999px;
    background: #d2edd7;
    color: #145324;
    font-size: 13px;
    font-weight: 700;
}

#cameraPreview {
    width: 100%;
    height: 100%;
    min-width: 1px;
    min-height: 1px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border: 0;
    border-radius: 50%;
    background: #172018;
}

.camera-frame {
    position: relative;
    width: min(100%, 78vh, 780px);
    aspect-ratio: 1;
    flex: none;
    border: 3px solid #12341a;
    border-radius: 50%;
    overflow: visible;
    background: #172018;
}

.readonly-page:has(#readerControls) .layout {
    grid-template-columns: minmax(0, 1fr);
}

.readonly-page:has(#readerControls) .work {
    display: none;
}

.readonly-page .work[hidden] {
    display: none;
}

.readonly-page:has(#readerControls) .panel {
    width: min(100%, 900px);
    margin: auto;
    align-items: center;
}

.readonly-page:has(#readerControls) #readerControls {
    width: min(100%, 900px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.readonly-page:has(#readerControls) #cameraPreview {
    width: min(100%, 900px);
    height: 100%;
    max-height: none;
    aspect-ratio: 1 / 1;
}

#resultActions {
    display: flex;
    width: min(100%, 420px);
    flex-direction: column;
    gap: 8px;
}

#resultActions[hidden] {
    display: none;
}

#voiceStatus {
    margin: 0;
    font-size: 12px;
    text-align: center;
}

#receivedArt {
    image-rendering: pixelated;
}

.corner-zone {
    position: fixed;
    z-index: 20;
    bottom: 0;
    width: 112px;
    height: var(--corner-height, clamp(110px, 25vh, 220px));
    min-width: 112px;
    min-height: var(--corner-height, clamp(110px, 25vh, 220px));
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 3px solid #14213d;
    border-radius: 0px;
    font-size: 25px;
    line-height: 1;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.corner-zone span {
    font-size: 12px;
}

.corner-undo {
    left: 0;
    margin-left: env(safe-area-inset-left);
    background: #dbe7ff;
    border-radius: 16px 16px 0px 0px;
}

.corner-talk {
    right: 0;
    margin-right: env(safe-area-inset-right);
    background: #ffd5d5;
    border-radius: 16px 16px 0px 0px;
}

.corner-talk.on {
    background: #c00000;
    color: #fff;
}




@media (max-width: 650px), (max-width: 900px) and (orientation: portrait) {

    :root {
       
        --button-size: clamp(44px, calc(6.2 * var(--dvh)), 52px);
        --palette-button-width: clamp(40px, calc((100vw - 40px) / 7), 76px);
        --h-describe: clamp(56px, calc(8.6 * var(--dvh)), 72px);
        --h-usage: clamp(48px, calc(7 * var(--dvh)), 60px);
        --h-sub: clamp(40px, calc(5.4 * var(--dvh)), 46px);
        --fs-describe: clamp(22px, 6vw, 30px);
        --fs-usage: clamp(16px, 4.4vw, 22px);
       
        --portrait-reserve: calc(2 * var(--button-size) + var(--h-describe) + var(--h-usage) + var(--h-sub) + 150px);
    }

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

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


   

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


   

    .work {
        display: flex;
        overflow: hidden;
        min-height: 0;
        flex-direction: column;
        gap: 3px;
    }

    .canvas-area {
        width: 100%;
        min-height: 0;
        flex: 1 1 auto;
    }

   
    .canvas-wrap {
        width: min(92vw, 100%, calc(100 * var(--dvh) - var(--portrait-reserve)));
        height: auto;
        max-width: min(92vw, 100%);
        aspect-ratio: 1 / 1;
    }

   
    @supports (container-type: size) {
        .canvas-area {
            container-type: size;
        }

        .canvas-wrap {
            width: min(92cqw, calc(100cqh - 24px));
        }
    }

    .canvas-area .stat {
        flex: none;
    }


   

    .tools {
        align-items: center;
        flex: none;
    }

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

    .palette-row {
        display: grid;
        grid-template-columns: repeat(7, var(--palette-button-width));
        gap: 3px;
    }

    .palette .swatch {
        grid-column: auto;
    }

    .palette .pen,
    .palette #undo {
        grid-column: auto;
        grid-row: auto;
    }

   

    .panel {
        width: min(95%, calc(95% - 140px));
        margin: 0 auto;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-content: start;
        overflow: hidden;
        padding: 5px 6px;
        gap: 4px 6px;
    }

    .panel > * {
        grid-column: 1 / -1;
    }

   
    #heard,
    #said {
        min-height: 2.7em;
        max-height: 2.7em;
        -webkit-line-clamp: 2;
    }

    .panel button {
        min-height: var(--h-sub);
        padding: 3px 6px;
        font-size: 15px;
        line-height: 1.1;
    }

    .panel #saveArtwork {
        width: 100%;
        min-width: 0;
    }

    .panel .share-actions {
        grid-column: span 2;
        gap: 4px;
    }

    .panel .share-actions button {
        padding-inline: 3px;
        overflow-wrap: anywhere;
    }

    .panel-qr {
        overflow: auto;
        padding: 6px;
        gap: 4px;
    }

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

    .panel .help {
        display: none;
    }

    .panel #describe,
    .panel .clear-actions {
        width: 100%;
        grid-column: 1 / -1;
    }

    .panel .voice-actions {
        grid-column: 1 / -1;
    }

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

    .readonly-page:has(#readerControls) .panel {
        width: 100%;
        padding: 4px;
    }

    .readonly-page:has(#readerControls) #cameraPreview {
        width: 100%;
        height: 100%;
        min-height: 0;
        border-radius: 50%;
    }

    .readonly-page:has(#readerControls) .camera-frame {
        width: min(100%, calc(100dvh - 210px));
    }
    .panel #describe {
        background: #cdddff;
        font-weight: 900 !important;
        font-size: var(--fs-describe) !important;
    }

   

    .listen {
        min-height: 58px !important;
        font-size: 22px !important;
    }


   

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

    .corner-zone {
        width: 82px;
        min-width: 82px;
    }
}




@media (max-width: 370px) {
    .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;
    }

}




@media (orientation: landscape) and (max-height: 450px) and (min-width: 651px) {

    :root {
        --button-size: clamp(32px, calc((100 * var(--dvh) - 40px) / 7), 48px);
        --palette-button-width: clamp(44px, 6vw, 56px);
        --h-describe: 56px;
        --h-usage: 46px;
        --h-sub: 38px;
        --fs-describe: 20px;
        --fs-usage: 17px;
    }

    .work {
        padding-left: 96px;
    }

   
    .readonly-page .work {
        padding-left: 0;
    }

    .corner-zone {
        width: 88px;
        min-width: 88px;
    }

    .palette {
        grid-template-columns: repeat(2, var(--palette-button-width));
    }

    .palette .swatch {
        grid-column: auto;
    }

    .palette .pen {
        grid-column: 1;
        grid-row: 7;
    }

    .palette #undo {
        grid-column: 2;
        grid-row: 7;
    }

    .panel {
        gap: 4px;
        padding: 6px 6px calc(var(--corner-height, clamp(110px, 25vh, 220px)) + 6px);
    }

    .panel button {
        padding: 2px 6px;
    }

    #heard,
    #said {
        min-height: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .help {
        display: none;
    }
}