*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
:root {
    --bg: #e7e5e4;
    --text: #292524;
    --btn-shadow: 2px 2px 4px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    --btn-active-shadow: 0 0 2px rgba(0, 0, 0, 0.2), inset 0 2px 3px rgba(0, 0, 0, 0.2);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-weight: bold;
    font-family: 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    touch-action: manipulation;
}
#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-bottom: var(--safe-bottom);
}
/* ===== 上部エリア ===== */
#top-area {
    position: relative;
    height: 14%;
    min-height: 0;
    flex-shrink: 0;
    padding: 16px 56px 16px 16px;
}
#output {
    width: 100%;
    height: 100%;
    background: #fafaf9;
    border: 2px solid var(--text);
    border-radius: 6px;
    box-shadow: var(--btn-shadow);
    resize: none;
    font-weight: bold;
    color: var(--text);
    font-family: inherit;
    line-height: 1.0;
    padding: 4px 6px;
    overflow: hidden;
    cursor: default;
    white-space: pre-wrap;
    word-break: break-all;
    display: flex;
    align-items: center;
    /* 上下中央揃え */
    justify-content: flex-start;
    /* 左寄せ（中央にしたい場合は center） */
}
#copy-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    background: #fafaf9;
    border: 2px solid var(--text);
    border-radius: 6px;
    box-shadow: var(--btn-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}
#copy-btn:active {
    box-shadow: var(--btn-active-shadow);
    transform: translateY(1px);
}
#copy-btn svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}
/* ===== 中部エリア（文字盤） ===== */
#middle-area {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: row;
    padding: 16px;
    gap: 16px;
    overflow: hidden;
}
/* ===== 左カラム ===== */
#left-col {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    flex-shrink: 0;
    /* right-col が flex:1 で kana-grid が10列なので
       left-col を同じ flex:1 にしつつ max-width で1列分に収める */
    max-width: calc(100% / 11);
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-left: 16px;
    margin-right: 24px;
    overflow: hidden;
}
.ctrl-btn {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    border: 2px solid var(--text);
    border-radius: 6px;
    box-shadow: var(--btn-shadow);
    background: #fafaf9;
    color: var(--text);
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 1px;
    position: relative;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:active {
    box-shadow: var(--btn-active-shadow);
    transform: translateY(1px);
}
.ctrl-btn svg {
    width: clamp(10px, 50%, 28px);
    height: clamp(10px, 50%, 28px);
    flex-shrink: 0;
    pointer-events: none;
}
.ctrl-btn .btn-label {
    font-size: clamp(7px, 1.5vw, 16px);
    line-height: 1.1;
    margin-top: 1px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
}
#speak-btn.has-text {
    background: #86efac;
    border-color: #16a34a;
}
#speak-btn.has-text svg polygon {
    fill: #15803d;
}
.char-mod-btn {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    border: 2px solid var(--text);
    border-radius: 6px;
    box-shadow: var(--btn-shadow);
    background: #fef9c3;
    color: var(--text);
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 1px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}
.char-mod-btn:active {
    box-shadow: var(--btn-active-shadow);
    transform: translateY(1px);
}
.char-mod-btn .mod-char {
    font-size: clamp(8px, 4vw, 40px);
    line-height: 1.0;
    text-align: center;
}
/* ===== 右カラム ===== */
#right-col {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-right: 16px;
    overflow: hidden;
}
/* 50音グリッド */
#kana-grid {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: row-reverse;
    gap: 16px;
    overflow: hidden;
}
#kana-grid.flipped {
    flex-direction: row;
}
.kana-col {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.kana-btn {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    border: 2px solid var(--text);
    border-radius: 4px;
    box-shadow: var(--btn-shadow);
    background: #fafaf9;
    color: var(--text);
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 1px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.0;
    position: relative;
}
.kana-btn:active {
    box-shadow: var(--btn-active-shadow);
    transform: translateY(1px);
}
.kana-btn.empty {
    background: #e7e5e4;
    border-color: #a8a29e;
    cursor: default;
    box-shadow: none;
}
.kana-btn.punct {
    background: #e0f2fe;
    border-color: #0284c7;
}
.kana-btn span {
    font-size: clamp(8px, 3vw, 48px);
    line-height: 1.0;
    pointer-events: none;
    display: block;
    text-align: center;
    position: relative;
    z-index: 500;
}
/* 数字行 */
#num-row {
    height: 10%;
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    gap: 16px;
    overflow: hidden;
}
.num-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    border: 2px solid var(--text);
    border-radius: 4px;
    box-shadow: var(--btn-shadow);
    background: #f0fdf4;
    color: var(--text);
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.0;
    position: relative;
}
.num-btn:active {
    box-shadow: var(--btn-active-shadow);
    transform: translateY(1px);
}
.num-btn span {
    font-size: clamp(8px, 2.5vw, 36px);
    line-height: 1.0;
    pointer-events: none;
    display: block;
    position: relative;
    z-index: 1;
}
/* ===== 視線コントロールバー ===== */
#gaze-bar {
    flex-shrink: 0;
    background: #1c1917;
    color: #fafaf9;
    display: flex;
    align-items: center;
    height: 44px;
    overflow: hidden;
}
#gaze-toggle-btn {
    height: 100%;
    width: 140px;
    flex-shrink: 0;
    padding: 0 10px;
    background: #44403c;
    border: none;
    border-right: 2px solid #57534e;
    color: #fafaf9;
    font-weight: bold;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    user-select: none;
}
#gaze-toggle-btn:active {
    background: #57534e;
}
#gaze-toggle-btn.on {
    background: #d97706;
    border-right-color: #b45309;
}
#gaze-toggle-btn.on:active {
    background: #b45309;
}
#gaze-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #78716c;
    flex-shrink: 0;
    transition: background 0.2s;
}
#gaze-toggle-btn.on #gaze-indicator {
    background: #fef08a;
    box-shadow: 0 0 6px rgba(254, 240, 138, 0.8);
}
.gaze-slider-group {
    width: 200px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border-right: 1px solid #44403c;
}
.gaze-slider-label {
    font-size: 11px;
    color: #d6d3d1;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.2;
}
.gaze-slider-group input[type=range] {
    flex: 1 1 0;
    min-width: 0;
    accent-color: #fbbf24;
    height: 4px;
    cursor: pointer;
}
.gaze-slider-val {
    font-size: 11px;
    color: #fbbf24;
    font-weight: bold;
    white-space: nowrap;
    width: 32px;
    text-align: right;
    flex-shrink: 0;
}
#margin-group {
    background: rgba(251, 191, 36, 0.08);
}
/* ===== 左右反転ボタン ===== */
#flip-btn {
    height: 100%;
    flex-shrink: 0;
    padding: 0 14px;
    background: #44403c;
    border: none;
    border-left: 1px solid #57534e;
    color: #d6d3d1;
    font-weight: bold;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
    user-select: none;
}
#flip-btn:active {
    background: #57534e;
}
#flip-btn.on {
    background: #0369a1;
    color: #e0f2fe;
}
#flip-btn.on:active {
    background: #075985;
}
#flip-btn svg {
    width: 16px;
    height: 16px;
    pointer-events: none;
    flex-shrink: 0;
}
/* ===== gaze ビジュアル ===== */
.gaze-glow {
    position: fixed;
    pointer-events: none;
    z-index: 350;
    border-radius: 6px;
    border: 3px solid rgba(251, 191, 36, 0.55);
    background: rgba(251, 191, 36, 0.20);
    /* ★追加：薄い黄色で塗りつぶす */
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.35);
}
.gaze-progress {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    pointer-events: none;
    z-index: 600;
    overflow: visible;
}
.gaze-progress circle {
    fill: none;
    stroke: #f59e0b;
    stroke-width: 4;
    stroke-linecap: round;
    transform-origin: center;
    transform: rotate(-90deg);
    filter: drop-shadow(0 0 3px rgba(251, 191, 36, 0.8));
}
.gaze-active {
    outline: 3px solid #f59e0b !important;
    outline-offset: 1px;
    background-color: rgba(251, 191, 36, 0.18) !important;
}
/* トースト */
#toast {
    position: fixed;
    bottom: 56px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #292524;
    color: #fafaf9;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 999;
    white-space: nowrap;
}
#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
@media (orientation: portrait) {
    #middle-area {
        flex-direction: column;
    }
    #left-col {
        max-width: 100%;
        width: 100%;
        flex-direction: row;
        flex: 0 0 auto;
        margin-left: 0;
        margin-right: 0;
        gap: 8px;
        margin-bottom: 24px;
    }
    #left-col .ctrl-btn,
    #left-col .char-mod-btn {
        flex: 1 1 0;
        min-height: 0;
        height: clamp(48px, 10vh, 80px);
    }
    #right-col {
        flex: 1 1 0;
        margin-right: 0;
    }
}