:root {
    --background-primary: #313338;
    --background-secondary: #2b2d31;
    --background-tertiary: #1e1f22;
    --text-normal: #dbdee1;
    --text-muted: #949ba4;
    --text-link: #5865f2;
    --green: #2dc770;
    --red: #f23f42;
    --yellow: #faa61a;
    --interactive-normal: #b5bac1;
    --interactive-hover: #dcdee1;
    --interactive-active: #fff;
}

body {
    background-color: var(--background-primary);
    color: var(--text-normal);
    font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* App Container and basic elements */
#app-container {
    width: 90%;
    max-width: 360px;
    background-color: var(--background-secondary);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
}

h1, h2 { color: #fff; margin-top: 0; font-weight: 700; }
h3 { font-size: 12px; font-weight: 700; line-height: 16px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; margin-top: 20px; }
#auth-screen h3:first-of-type { margin-top: 0; }
.modal-body h3:first-of-type { margin-top: 0; }


hr { border: none; border-top: 1px solid var(--background-tertiary); margin: 20px 0; }
.modal-divider { height: 1px; background-color: var(--background-tertiary); margin: 20px 0; }
.divider { display: flex; align-items: center; text-align: center; color: var(--text-muted); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--background-tertiary); }
.divider:not(:empty)::before { margin-right: .5em; }
.divider:not(:empty)::after { margin-left: .5em; }

input[type="text"], select { width: 100%; padding: 10px; margin-top: 8px; border-radius: 3px; border: 1px solid var(--background-tertiary); background-color: var(--background-tertiary); color: var(--text-normal); box-sizing: border-box; font-size: 16px; }
select { margin-bottom: 0; }
#token-input { margin-bottom: 10px; }

button { width: 100%; padding: 12px; border: none; border-radius: 3px; background-color: var(--text-link); color: #fff; font-size: 16px; font-weight: 500; cursor: pointer; transition: background-color 0.17s ease; }
button:hover { background-color: #4752c4; }
#login-discord-btn { background-color: #7289da; }
#login-discord-btn:hover { background-color: #677bc4; }

/* Chat Screen */
#chat-screen .header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--background-tertiary); padding-bottom: 10px; margin-bottom: 15px; }
#chat-screen .user-info { font-size: 14px; color: var(--text-muted); }
#my-username { color: var(--text-normal); font-weight: 600; }

#player-list ul { list-style-type: none; padding: 0; max-height: 250px; overflow-y: auto; }
#players li { padding: 10px; border-radius: 4px; display: flex; align-items: center; justify-content: space-between; transition: background-color 0.1s, border-color 0.1s; border: 2px solid transparent; margin-bottom: 5px; }
#players li.speaking { background-color: rgba(45, 199, 112, 0.1); border-color: var(--green); }
.player-info { display: flex; flex-direction: column; gap: 4px; }
.player-name { font-weight: 500; }
.player-status { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.status-checking { color: var(--yellow); }
.status-connected, .status-completed { color: var(--green); }
.status-failed, .status-disconnected, .status-closed { color: var(--red); }
.status-new { color: var(--text-muted); }

.volume-slider { width: 100px; }

.controls { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#mute-btn.muted { background-color: var(--red); }
#mute-btn.muted:hover { background-color: #d84040; }
#settings-btn { background-color: #4f545c; }
#settings-btn:hover { background-color: #5d636b; }

/* Modal Styles */
.modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); display: flex; justify-content: center; align-items: center; z-index: 2000; }
.modal-content {
    background-color: var(--background-secondary); padding: 24px;
    border-radius: 8px; width: 90%; max-width: 480px;
    display: flex; flex-direction: column;
    max-height: 90vh; /* 画面の高さを超えないようにする */
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-shrink: 0; }
.close-btn { background: none; border: none; font-size: 24px; color: var(--interactive-normal); cursor: pointer; padding: 0; line-height: 1; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.close-btn:hover { color: var(--interactive-hover); }

/* ★★★ 修正箇所 ★★★ */
.modal-body {
    display: flex; flex-direction: column; gap: 16px;
    overflow-y: auto; /* コンテンツがはみ出したらスクロール */
    padding-right: 12px; /* スクロールバーのための余白 */
    margin-right: -12px; /* スクロールバーの幅を相殺 */
}

.setting-group { display: flex; flex-direction: column; gap: 8px; }
.setting-item { display: flex; justify-content: space-between; align-items: center; }
.setting-item label { font-weight: 500; font-size: 14px; color: var(--text-normal); }
small { font-size: 12px; color: var(--text-muted); }

.volume-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.mic-test-bar { width: 100%; height: 8px; background-color: var(--background-tertiary); border-radius: 4px; overflow: hidden; position: relative; }
.mic-test-meter-level { width: 0%; height: 100%; background-color: var(--green); border-radius: 4px; transition: width 0.05s linear; }
.vad-threshold-marker { position: absolute; top: 0; height: 100%; width: 2px; background-color: var(--interactive-hover); transition: left 0.1s ease; }

.modal-footer { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--background-tertiary); text-align: right; flex-shrink: 0; }
.modal-footer button { width: auto; padding: 10px 24px; }


/* Switch & Slider Styles */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #4f545c; transition: .2s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 2px; bottom: 2px; background-color: white; transition: .2s; border-radius: 50%; }
input:checked + .slider { background-color: var(--green); }
input:checked + .slider:before { transform: translateX(20px); }

input[type=range] { -webkit-appearance: none; background: transparent; cursor: pointer; width: 100%; }
input[type=range]::-webkit-slider-runnable-track { background: #43464d; height: 4px; border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 16px; width: 16px; background: var(--interactive-normal); border-radius: 50%; margin-top: -6px; border: 1px solid var(--background-tertiary); }
input[type=range]:hover::-webkit-slider-thumb { background: var(--interactive-hover); }

/* Audio Overlay */
#audio-start-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.85); color: white; display: flex; justify-content: center; align-items: center; text-align: center; z-index: 1000; cursor: pointer; flex-direction: column; }
