/* =========================================
   1. Root & Base Styles
   ========================================= */
:root {
    --bg-dark: #111111;
    --bg-card: #222222;
    --primary: #f59e0b;
    --primary-glow: rgba(245, 158, 11, 0.5);
    --secondary: #d97706;
    --secondary-glow: rgba(217, 119, 6, 0.5);
    --text-main: #f8fafc;
    --text-muted: #9ca3af;
    --border: #404040;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Zen Kaku Gothic New', sans-serif;
    --glass: rgba(34, 34, 34, 0.8);
    --transition-fast: 0.3s ease;
    --transition-slow: 0.5s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(245, 158, 11, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(255, 255, 255, 0.05) 0%, transparent 20%);
    overflow-x: hidden;
}

/* =========================================
   2. Layout
   ========================================= */
.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.split-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
    align-items: center;
    animation: fadeIn 0.8s ease-out;
}

/* =========================================
   3. Header & Navigation
   ========================================= */
.app-header {
    text-align: center;
    margin-bottom: 1rem;
}

.app-header h1 {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.05em;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 10px var(--primary-glow));
}

.app-header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

#help-btn {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#help-btn:hover {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--primary-glow);
}

/* =========================================
   4. Entry Mode & Upload Section
   ========================================= */
.upload-section {
    width: 100%;
    max-width: 600px;
    animation: fadeIn 0.8s ease-out;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.entry-mode-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.mode-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    cursor: pointer;
    position: relative;
    transition: var(--transition-fast);
}

.mode-tab:after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--primary);
    transition: var(--transition-fast);
    transform: translateX(-50%);
}

.mode-tab.active {
    color: var(--primary);
}

.mode-tab.active:after {
    width: 100%;
}

.file-drop-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    border: 2px dashed var(--border);
    border-radius: 1rem;
    background: var(--glass);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    cursor: pointer;
}

.file-drop-area:hover,
.file-drop-area.dragover {
    border-color: var(--primary);
    background: rgba(245, 158, 11, 0.05);
    box-shadow: 0 0 20px var(--primary-glow);
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.file-msg {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.file-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.format-hint,
.security-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.security-hint {
    margin-top: 0.5rem;
    opacity: 0.8;
}

/* --- Manual Entry Form --- */
.manual-entry-form {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-input,
.form-textarea {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-family: var(--font-body);
    outline: none;
    transition: var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.form-input {
    flex: 1;
}

.form-textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
}

.btn-small {
    padding: 0.5rem 1.5rem;
    font-size: 0.9rem;
    align-self: flex-end;
}

/* --- Preview List --- */
.manual-list-container {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

.manual-list-header {
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.manual-preview-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
}

.manual-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0.5rem;
    margin-bottom: 0.25rem;
}

.manual-item:last-child {
    border-bottom: none;
}

.manual-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.manual-item-name {
    font-weight: 700;
    font-size: 1rem;
}

.manual-item-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.remove-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.2rem 0.5rem;
    transition: var(--transition-fast);
}

.remove-btn:hover {
    transform: scale(1.2);
}

.empty-msg {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-style: italic;
}

.manual-controls {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* =========================================
   5. Presenter Tabs
   ========================================= */
.presenter-section {
    width: 100%;
    text-align: center;
    animation: slideUp 0.5s ease-out;
}

.presenter-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.presenter-tab {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--font-body);
    font-weight: 700;
}

.presenter-tab:hover {
    background: var(--border);
}

.presenter-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    box-shadow: 0 4px 15px var(--primary-glow);
    transform: translateY(-2px);
}

/* =========================================
   6. Settings & Candidates
   ========================================= */
.settings-candidate-section {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: fadeIn 0.5s ease-out;
}

.settings-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--glass);
    border-radius: 2rem;
    border: 1px solid var(--border);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-card);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(16px);
    background-color: white;
}

.winner-count-selector {
    display: flex;
    gap: 0.5rem;
}

.count-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.count-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

.candidate-list-container {
    background: var(--bg-card);
    border-radius: 1rem;
    border: 1px solid var(--border);
    overflow: hidden;
}

.candidate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: transform 0.3s;
}

.search-container {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.search-input {
    width: 100%;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-main);
    outline: none;
    transition: var(--transition-fast);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.candidate-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    transition: max-height 0.3s ease;
}

.candidate-list.collapsed {
    max-height: 0;
    padding: 0;
}

.candidate-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.candidate-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.candidate-item input[type="checkbox"] {
    margin-right: 1rem;
    accent-color: var(--primary);
}

.candidate-item.winner {
    opacity: 0.5;
    text-decoration: line-through;
    color: var(--text-muted);
}

/* =========================================
   7. Roulette Wheel & Pointers
   ========================================= */
.roulette-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    animation: zoomIn 0.8s ease-out;
}

.roulette-container {
    position: relative;
    width: 500px;
    height: 500px;
    max-width: 90vw;
    max-height: 90vw;
}

.roulette-wheel-outer {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    background: var(--bg-card);
}

#roulette-canvas {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.pointers-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.pointer {
    position: absolute;
    font-size: 3rem;
    color: var(--text-main);
    filter: drop-shadow(0 0 5px var(--secondary));
    transition: var(--transition-slow);
}

#pointer-1 {
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
}

#pointer-2 {
    top: 75%;
    left: 93%;
    transform: translate(-50%, -50%) rotate(120deg);
}

#pointer-3 {
    top: 75%;
    left: 7%;
    transform: translate(-50%, -50%) rotate(240deg);
}

.mode-2 #pointer-1 {
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
}

.mode-2 #pointer-2 {
    top: auto;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%) rotate(180deg);
}

/* =========================================
   8. Controls
   ========================================= */
.controls {
    display: flex;
    gap: 1rem;
}

.btn {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    padding: 1rem 3rem;
    border: none;
    border-radius: 3rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 10px 20px -5px var(--primary-glow);
}

.btn-primary:active {
    transform: scale(0.95);
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-muted);
}

.btn-secondary:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

/* =========================================
   9. Modals (Result & Help)
   ========================================= */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: 1.5rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    /* 画面の高さを超えないように制限 */
    display: flex;
    flex-direction: column;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: popUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    /* コンテンツが多い場合はボディー内でスクロール */
    padding-right: 0.5rem;
    margin-bottom: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.result-name {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1rem;
    text-shadow: 0 0 20px var(--primary-glow);
}

.result-question {
    font-size: 1.2rem;
    color: var(--text-main);
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: 1rem;
    max-width: 100%;
    /* 親要素に合わせる */
    margin: 0 auto;
    white-space: pre-wrap;
    /* 改行を保持 */
    word-break: break-word;
    /* 長い単語でも折り返す */
    max-height: 300px;
    /* 長すぎる場合はスクロール */
    overflow-y: auto;
    text-align: left;
    /* 長文は見やすく左寄せ */
}

/* --- Side Entry (Roulette View) --- */
.side-entry-container {
    background: var(--bg-card);
    border-radius: 1rem;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-top: 0.5rem;
}

.side-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: rgba(245, 158, 11, 0.05);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.side-entry-header h3 {
    font-size: 1rem;
    color: var(--primary);
}

.side-entry-body {
    transition: max-height 0.4s ease-out, padding 0.4s ease-out;
    max-height: 500px;
    background: rgba(255, 255, 255, 0.02);
}

.side-entry-body.collapsed {
    max-height: 0;
    padding: 0;
    overflow: hidden;
}

.side-form {
    padding: 1rem !important;
    background: transparent !important;
    border: none !important;
    gap: 0.75rem !important;
}

.side-form .form-input,
.side-form .form-textarea {
    font-size: 0.9rem;
    padding: 0.6rem 0.8rem;
}

.side-form .form-textarea {
    min-height: 60px;
}

.result-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    animation: slideUp 0.5s ease-out;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item .result-name {
    font-size: 1.8rem;
}

.result-item .result-question {
    font-size: 1rem;
    padding: 1rem;
    border-radius: 0.8rem;
    text-align: left;
    white-space: pre-wrap;
    /* 改行を保持 (複数当選時) */
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.modal-content.multi-winner {
    max-width: 600px;
    padding: 1.5rem;
}

.help-step {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.help-step:last-child {
    border-bottom: none;
}

.help-step h4 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.help-step p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.help-badge {
    background: var(--primary);
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
}

/* =========================================
   10. System utilities
   ========================================= */
.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes popUp {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* =========================================
   11. Media Queries
   ========================================= */
@media (min-width: 768px) {
    .split-layout {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 3rem;
    }

    .settings-candidate-section {
        flex: 1;
        max-width: 400px;
        position: sticky;
        top: 2rem;
    }

    .roulette-section {
        flex: 2;
        max-width: 600px;
    }

    .candidate-list {
        max-height: 500px;
    }
}

@media (max-width: 600px) {
    .app-header h1 {
        font-size: 2.5rem;
    }

    .btn {
        padding: 0.75rem 2rem;
        font-size: 1rem;
    }

    .roulette-container {
        width: 300px;
        height: 300px;
    }
}