/* CH9329 WebSerial Controller Styles */

:root {
    /* プライマリカラー（背景用） */
    --primary: #57bf80;

    /* ボタン専用カラー */
    --button-start: #57bf80;
    --button-end: #39925c;
    --button-disabled: #ccc;

    /* 背景色 */
    --bg-main: white;
    --bg-section: #f7f7f7;
    --bg-keyboard: #79987e;
    --bg-log: #1e1e1e;
    
    /* ボーダー */
    --border-section: #e0e0e0;
    --border-input: #e0e0e0;

    /* 入力要素 */
    --input-bg: white;
    --input-text: #333;

    /* キーボードキー */
    --key-button-light: #f0f0f0;
    --key-button-dark: #d0d0d0;
    --key-border: #999;
    
    /* タッチパッド */
    --touchpad-bg-light: #e0e0e0;
    --touchpad-bg-dark: #d0d0d0;
    --touchpad-border: #999;
    --touchpad-scrolling-light: #8ab58e;
    --touchpad-scrolling-dark: #4f704e;

    /* テキスト */
    --text-primary: #333;
    --text-secondary: #555;
    --text-muted: #717171;
    
    /* アクセントカラー */
    --accent-error: #dc3545;
    --accent-scroll: #4ae25c;

    /* その他 */
    --log-text: #0f0;
    --shadow: rgba(0,0,0,0.2);
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    :root {
        /* プライマリカラー（背景用） */
        --primary: #2a4432;

        /* ボタン専用カラー */
        --button-start: #39925c;
        --button-end: #166240;
        --button-disabled: #4a4a4a;
        
        /* 背景色 */
        --bg-main: #101010;
        --bg-section: #2b2b2b;
        --bg-keyboard: #101010;
        --bg-log: #0a0a0a;
        
        /* ボーダー */
        --border-section: #5e625f;
        --border-input: #404040;

        /* 入力要素 */
        --input-bg: #101010;
        --input-text: #e8e8e8;

        /* キーボードキー */
        --key-button-light: #404040;
        --key-button-dark: #303030;
        --key-border: #606060;
        
        /* タッチパッド */
        --touchpad-bg-light: #404040;
        --touchpad-bg-dark: #303030;
        --touchpad-border: #606060;
        --touchpad-scrolling-light: #2a4a3a;
        --touchpad-scrolling-dark: #1a3a2a;

        /* テキスト */
        --text-primary: #e8e8e8;
        --text-secondary: #dddddd;
        --text-muted: #b8b8b8;
        
        /* アクセントカラー */
        --accent-error: #ef4444;
        --accent-scroll: #4ae25c;

        /* その他 */
        --log-text: #10b981;
    }
}

html {
    background: var(--primary);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: var(--primary);
    min-height: 100vh;
}

.container {
    background: var(--bg-main);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px var(--shadow);
}

h1 {
    color: var(--text-primary);
    border-bottom: 3px solid var(--primary);
    padding-bottom: 10px;
    margin-bottom: 30px;
}

label {
    color: var(--text-muted);
}

.section {
    margin: 25px 0;
    padding: 20px;
    background: var(--bg-section);
    border-radius: 10px;
    border: 1px solid var(--border-section);
}

.section h2 {
    color: var(--text-secondary);
    margin-top: 0;
    font-size: 1.3em;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
    margin-bottom: 15px;
}

button {
    background: linear-gradient(135deg, var(--button-start) 0%, var(--button-end) 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 32px;
    cursor: pointer;
    font-size: 16px;
    margin: 5px;
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-light);
}

button:disabled {
    background: var(--button-disabled);
    cursor: not-allowed;
    transform: none;
}

button:active:not(:disabled) {
    transform: translateY(0);
}

textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-input);
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s;
    box-sizing: border-box;
    background: var(--input-bg);
    color: var(--input-text);
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    min-height: 100px;
    font-family: 'Courier New', monospace;
    resize: vertical;
}

.status-tag {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    margin-left: 10px;
    vertical-align: middle;
    transition: all 0.3s;
}

.status-tag.connected {
    background: var(--button-start);
    color: white;
}

.status-tag.disconnected {
    background: var(--accent-error);
    color: white;
}


.touchpad {
    width: 360px;
    height: 200px;
    background: linear-gradient(180deg, var(--touchpad-bg-light) 0%, var(--touchpad-bg-dark) 100%);
    border: 1px solid var(--touchpad-border);
    border-radius: 8px;
    margin: 20px auto;
    position: relative;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    overflow: hidden;
    box-shadow: inset 0 1px 3px var(--shadow);
}

.touchpad-area {
    width: 100%;
    height: 140px;
    position: relative;
    background: linear-gradient(180deg, var(--key-button-light) 0%, var(--touchpad-bg-light) 100%);
    border-bottom: 1px solid var(--touchpad-border);
}

.touchpad-area.scrolling {
    background: linear-gradient(180deg, var(--touchpad-scrolling-light) 0%, var(--touchpad-scrolling-dark) 100%);
}

.touchpad-area.capture-active {
    background: linear-gradient(180deg, var(--touchpad-scrolling-light) 0%, var(--touchpad-scrolling-dark) 100%);
}

.touchpad-buttons {
    display: flex;
    height: 60px;
    position: relative;
}

.touchpad-button {
    flex: 1;
    background: linear-gradient(180deg, var(--touchpad-bg-light) 0%, var(--touchpad-bg-dark) 100%);
    border: none;
    position: relative;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
}

.touchpad-button.left {
    border-right: 1px solid var(--touchpad-border);
    border-bottom-left-radius: 7px;
}

.touchpad-button.middle {
    flex: 0.3;
    border-right: 1px solid var(--touchpad-border);
    position: relative;
}

.touchpad-button.right {
    border-bottom-right-radius: 7px;
}

.touchpad-button:hover {
    background: linear-gradient(180deg, var(--key-button-light) 0%, var(--touchpad-bg-light) 100%);
}

.touchpad-button.active {
    background: linear-gradient(135deg, var(--button-start) 0%, var(--button-end) 100%);
    box-shadow: inset 0 2px 4px var(--shadow);
    transform: translateY(1px);
}

.touchpad-button.capture-active {
    background: linear-gradient(180deg, var(--touchpad-scrolling-light) 0%, var(--touchpad-scrolling-dark) 100%);
}

.touchpad-button.click-feedback {
    background: linear-gradient(135deg, var(--button-start) 0%, var(--button-end) 100%);
}

.touchpad-button.scrolling {
    background: linear-gradient(180deg, var(--touchpad-scrolling-light) 0%, var(--touchpad-scrolling-dark) 100%);
}

.scroll-arrows {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    pointer-events: none;
}

.scroll-arrows .arrow {
    width: 0;
    height: 0;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.scroll-arrows .arrow.up {
    border-bottom: 6px solid var(--text-muted);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
}

.scroll-arrows .arrow.down {
    border-top: 6px solid var(--text-muted);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
}

.touchpad-button.middle.scrolling-up .scroll-arrows .arrow.up {
    opacity: 1;
    border-bottom-color: white;
}

.touchpad-button.middle.scrolling-down .scroll-arrows .arrow.down {
    opacity: 1;
    border-top-color: white;
}


select {
    padding: 10px;
    border: 2px solid var(--border-input);
    border-radius: 5px;
    font-size: 14px;
    margin: 5px 0;
    background: var(--input-bg);
    color: var(--input-text);
}

.log {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-log);
    color: var(--log-text);
    padding: 10px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin-top: 10px;
}

.log-entry {
    margin: 2px 0;
    opacity: 0;
    animation: fadeIn 0.3s ease-in forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}




.visual-keyboard {
    background: var(--bg-keyboard);
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
}

.visual-keyboard.realtime-active {
    background: var(--primary);
}

.keyboard-container {
    display: flex;
    gap: 20px;
}

.main-keyboard {
    flex: 1;
}

.special-keys-area {
    display: flex;
    flex-direction: column;
}

.keyboard-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    justify-content: center;
}

.nav-key-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.arrow-key-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    justify-content: center;
}

.nav-keys-section {
    margin-top: 0;
}

.arrow-keys-section {
    margin-top: 0;
}

.key {
    min-width: 40px;
    height: 40px;
    background: linear-gradient(180deg, var(--key-button-light) 0%, var(--key-button-dark) 100%);
    border: 1px solid var(--key-border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    color: var(--text-primary);
    transition: all 0.1s;
    box-shadow: 0 2px 4px var(--shadow);
    user-select: none;
    position: relative;
}

.key:hover {
    background: linear-gradient(180deg, var(--key-button-light) 0%, var(--touchpad-bg-light) 100%);
    filter: brightness(1.1);
}

.key:active, .key.pressed {
    transform: translateY(2px);
    box-shadow: inset 0 2px 4px var(--shadow);
    background: linear-gradient(135deg, var(--button-start) 0%, var(--button-end) 100%);
    color: white;
}

.key.space {
    min-width: 250px;
}

.key.backspace, .key.tab, .key.caps, .key.enter {
    min-width: 70px;
}

.key.shift {
    min-width: 90px;
}

.key.ctrl, .key.alt {
    min-width: 50px;
}

.key.cmd {
    min-width: 70px;
    font-size: 11px;
}

.key.win {
    min-width: 50px;
}

.key.menu {
    min-width: 50px;
    font-size: 11px;
}

.function-key {
    min-width: 35px;
    height: 35px;
    font-size: 10px;
}

.key.nav-key {
    min-width: 45px;
    font-size: 11px;
}

.key.arrow-key {
    font-size: 16px;
}


