/* リセットと基本スタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

/* ヘッダー */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
    position: relative;
}

.header-content {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.header-text {
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    color: #6366f1;
    margin-bottom: 10px;
}

.subtitle {
    color: #666;
    font-size: 1.1rem;
}

/* ヘルプボタン */
.help-button {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    transition: all 0.3s ease;
}

.help-button:hover {
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* タブナビゲーション */
.tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.tab-button {
    padding: 10px 20px;
    border: 2px solid #e5e7eb;
    background-color: white;
    color: #666;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.tab-button:hover {
    background-color: #f3f4f6;
    border-color: #6366f1;
}

.tab-button.active {
    background-color: #6366f1;
    color: white;
    border-color: #6366f1;
}

/* タブコンテンツ */
.tab-content {
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 30px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* チャレンジヘッダー */
.challenge-header, .results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.challenge-header h2, .results-header h2 {
    font-size: 1.8rem;
    color: #333;
}

.level {
    background-color: #fef3c7;
    color: #d97706;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
}

.challenge-description {
    background-color: #f0f9ff;
    border-left: 4px solid #3b82f6;
    padding: 15px;
    margin-bottom: 25px;
    border-radius: 4px;
}

/* 暗号文表示エリア */
.cipher-text {
    background-color: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    font-family: "Courier New", monospace;
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 25px;
    white-space: pre-wrap;
}

.cipher-line {
    display: flex;
    align-items: baseline;
    margin-bottom: 5px;
    line-height: 1.8;
}

.line-number {
    color: #9ca3af;
    width: 30px;
    text-align: right;
    margin-right: 15px;
    display: inline-block;
    vertical-align: baseline;
    flex-shrink: 0;
}

.cipher-line .first-char-initial {
    /* 初期状態では通常の文字と同じスタイル */
    color: inherit;
    font-weight: normal;
    display: inline;
    vertical-align: baseline;
}

/* ヒント表示 */
.hint-display {
    background-color: #fef3c7;
    border: 2px solid #fbbf24;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    font-size: 1.2rem;
    text-align: center;
}

.rule-display {
    background-color: #e0e7ff;
    border: 2px solid #6366f1;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
}

/* 入力エリア */
.answer-section {
    margin-bottom: 20px;
}

.answer-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #4b5563;
}

.answer-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1.1rem;
    margin-bottom: 15px;
}

.answer-input:focus {
    outline: none;
    border-color: #6366f1;
}

.remove-chars {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.char-input {
    width: 40px;
    height: 40px;
    text-align: center;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1.2rem;
}

.remove-chars-note {
    margin-top: 5px;
    margin-bottom: 10px;
    color: #6b7280;
    font-style: italic;
}

.remove-char-highlight {
    background-color: #fef3c7;
    color: #dc2626;
    font-weight: bold;
    padding: 1px 2px;
    border-radius: 2px;
}

/* ボタン */
.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.hint-button {
    background-color: #fbbf24;
    color: #78350f;
}

.hint-button:hover {
    background-color: #f59e0b;
}

.check-button {
    background-color: #34d399;
    color: white;
}

.check-button:hover {
    background-color: #10b981;
}

.next-button {
    background-color: #6366f1;
    color: white;
}

.next-button:hover {
    background-color: #4f46e5;
}

/* 進捗表示 */
.progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    color: #6b7280;
}

.progress-dots {
    font-size: 1.5rem;
    letter-spacing: 2px;
}

.progress-hint {
    font-size: 0.8rem;
    color: #9ca3af;
    font-style: italic;
    margin-left: 10px;
}

.current-problem-indicator {
    font-size: 0.9rem;
    color: #6366f1;
    font-weight: bold;
    margin-left: 5px;
    padding: 2px 8px;
    background-color: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* ステンシルチャレンジ特有のスタイル */
.stencil-container {
    position: relative;
    background-color: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    height: 300px;
    overflow: hidden;
}

.stencil-text {
    font-family: "Courier New", monospace;
    font-size: 1.2rem;
    line-height: 1.8;
}

.stencil-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.stencil-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.stencil-toggle {
    display: flex;
    gap: 10px;
}

.stencil-button {
    padding: 12px 20px;
    background-color: #6366f1;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

.stencil-button:hover {
    background-color: #4f46e5;
}

.stencil-move-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.stencil-move, .stencil-rotate {
    padding: 8px 16px;
    background-color: #e5e7eb;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.stencil-move:hover, .stencil-rotate:hover {
    background-color: #d1d5db;
}

/* 成果タブ */
.results-container {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
    align-items: start;
}

.chart-section {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: #fafafa;
    border-radius: 12px;
    min-height: 440px;
}

.chart-section canvas {
    max-width: 100%;
    height: auto;
}

.score-section h3 {
    margin-bottom: 15px;
    color: #4b5563;
    font-size: 1.3rem;
}

.score-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.score-label {
    width: 90px;
    font-weight: bold;
    flex-shrink: 0;
}

.score-dots {
    margin: 0 8px;
    flex: 1;
}

.score-percent {
    color: #6b7280;
    font-size: 0.9rem;
    min-width: 35px;
    text-align: right;
}

.total-score {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e5e7eb;
    font-size: 1.2rem;
}

.rank-display {
    text-align: center;
    background-color: #f0f9ff;
    border-radius: 12px;
    padding: 30px;
    margin: 40px 0;
    clear: both;
}

.rank-display h3 {
    font-size: 2rem;
    color: #6366f1;
    margin-bottom: 10px;
}

#rank {
    font-size: 2.5rem;
}

.share-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.share-button {
    background-color: #6366f1;
    color: white;
    padding: 12px 24px;
    font-size: 1rem;
}

.share-button:hover {
    background-color: #4f46e5;
}

/* ヘルプモーダル専用スタイル */
.modal-content.help-modal-content {
    max-width: 1000px !important;
    width: 95% !important;
    max-height: 90vh;
    margin: 5vh auto !important;
    padding: 60px 50px 30px 50px;
    text-align: left;
    overflow-y: auto;
    border-radius: 12px;
}

.help-modal-content h2 {
    color: #6366f1;
    margin-bottom: 20px;
    font-size: 1.8rem;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 10px;
}

.help-modal-content h3 {
    color: #374151;
    margin: 25px 0 15px 0;
    font-size: 1.3rem;
}

.help-modal-content p {
    line-height: 1.7;
    margin-bottom: 15px;
    color: #4b5563;
}

.help-modal-content ul {
    margin: 15px 0;
    padding-left: 25px;
}

.help-modal-content li {
    margin-bottom: 10px;
    color: #4b5563;
    line-height: 1.6;
}

.help-modal-content .challenge-type {
    background-color: #f0f9ff;
    border-left: 4px solid #6366f1;
    padding: 15px;
    margin: 15px 0;
    border-radius: 0 8px 8px 0;
}

.help-modal-content .challenge-type h4 {
    color: #6366f1;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.help-modal-content .tip {
    background-color: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 12px;
    margin: 15px 0;
    border-radius: 0 6px 6px 0;
    font-size: 0.95rem;
}

/* スタイリッシュな進捗ドット */
.progress-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin: 0 3px;
    transition: all 0.3s ease;
    position: relative;
}

/* ツールチップ表示 */
.progress-dot[title]:hover::before {
    content: attr(title);
    position: absolute;
    bottom: 150%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #1f2937;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
    opacity: 0.9;
}

.progress-dot[title]:hover::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1f2937;
    z-index: 100;
}

.progress-dot.pending {
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
    border: 2px solid #d1d5db;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-dot.completed {
    background: linear-gradient(135deg, #10b981, #059669);
    border: 2px solid #047857;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

.progress-dot.completed::after {
    content: '✓';
    position: absolute;
    top: -1px;
    left: 2px;
    color: white;
    font-size: 9px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.progress-dot:hover {
    transform: scale(1.1);
}

.progress-dot.completed:hover {
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

.progress-dot.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.progress-dot.clickable:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.progress-dot.current {
    border: 3px solid #6366f1;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.8), 0 0 5px rgba(99, 102, 241, 0.4);
    transform: scale(1.3);
    animation: pulse-current 2s infinite;
    z-index: 10;
    position: relative;
}

@keyframes pulse-current {
    0%, 100% {
        box-shadow: 0 0 15px rgba(99, 102, 241, 0.8), 0 0 5px rgba(99, 102, 241, 0.4);
    }
    50% {
        box-shadow: 0 0 25px rgba(99, 102, 241, 1), 0 0 10px rgba(99, 102, 241, 0.6);
    }
}

.progress-dot.incorrect {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border: 2px solid #b91c1c;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.progress-dot.incorrect::after {
    content: '×';
    position: absolute;
    top: -1px;
    left: 3px;
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 50px 30px 30px 30px;
    border-radius: 12px;
    width: 80%;
    max-width: 500px;
    max-height: 70vh;
    text-align: center;
    position: relative;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    right: 15px;
    top: 15px;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid #e5e7eb;
    font-size: 20px;
    cursor: pointer;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
}

.modal-close:hover {
    color: #374151;
    background-color: #f9fafb;
    border-color: #d1d5db;
    transform: scale(1.05);
}

/* フッター */
footer {
    text-align: center;
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid #e5e7eb;
    background-color: #f9fafb;
}

footer p {
    margin: 0;
    color: #6b7280;
    font-size: 0.9rem;
}

footer a {
    color: #6366f1;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

footer a:hover {
    color: #4f46e5;
    text-decoration: underline;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .tab-button {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
    
    .tab-content {
        padding: 20px;
    }
    
    .results-container {
        grid-template-columns: 1fr;
    }
    
    .chart-section {
        min-height: 320px;
        padding: 15px;
    }
    
    .button-group {
        justify-content: center;
    }
    
    .modal-content {
        width: 90%;
        margin: 5% auto;
        padding: 45px 20px 25px 20px;
        max-height: 80vh;
    }
    
    .modal-close {
        width: 30px;
        height: 30px;
        font-size: 18px;
        right: 10px;
        top: 10px;
    }
    
    .help-button {
        width: 35px;
        height: 35px;
        font-size: 18px;
        border-radius: 50%;
        min-width: 35px;
        min-height: 35px;
    }
    
    .modal-content.help-modal-content {
        width: 98% !important;
        max-width: 95vw !important;
        padding: 50px 25px 25px 25px;
        max-height: 95vh;
        margin: 2.5vh auto !important;
    }
    
    .help-modal-content h2 {
        font-size: 1.5rem;
    }
    
    .help-modal-content h3 {
        font-size: 1.2rem;
    }
}