/* フォント定義 */
@font-face {
    font-family: 'DSEG7';
    src: url('fonts/DSEG7Modern-Bold.woff2') format('woff2'),
         url('fonts/DSEG7Modern-Bold.ttf') format('truetype'); 
    font-weight: bold;
    font-style: normal;
}

:root {
    --c-white: #ffffff;
    --c-black: #111111;
    --c-red: #ff0000;
    --c-red-ud: #ff4b00;
    --c-yellow: #ffd900;
    --c-yellow-ud: #f29600;
    --c-green: #00ff00;
    --c-green-ud: #03af7a;
    --c-gray: #444444;
}

/* Dark Mode (Default) */
body {
    --bg-color: #000000;
    --text-default: var(--c-white);
    --ui-bg: #111;
    --ui-border: #333;
    --ui-text: #eee;
    --modal-bg: #222;
    --input-bg: #000;
    --input-border: #555;
    --btn-bg: #444;
    --title-text: #aaa;
    --current-border: #0066cc;
    --next-border: #666;
}

/* Light Mode */
body[data-theme="light"] {
    --bg-color: #f0f0f0;
    --text-default: var(--c-black);
    --ui-bg: #e0e0e0;
    --ui-border: #ccc;
    --ui-text: #111;
    --modal-bg: #fff;
    --input-bg: #fff;
    --input-border: #888;
    --btn-bg: #666;
    --title-text: #555;
    --current-border: #0066cc;
    --next-border: #999;
}

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

body {
    background-color: var(--bg-color);
    color: var(--ui-text);
    font-family: sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Receiver Mode */
body.receiver-mode .control-panel,
body.receiver-mode #settings-modal {
    display: none !important;
}
body.receiver-mode .title-container input { pointer-events: none; border-bottom: none; }
body.receiver-mode { cursor: none; }

/* Title Area */
.title-container {
    width: 100%; text-align: center; padding: 1rem 1rem 0 1rem;
    flex-shrink: 0; z-index: 5;
}
.title-container input {
    background: transparent; border: none; border-bottom: 1px dashed #444;
    color: var(--title-text); font-size: min(4vw, 2rem);
    text-align: center; width: 80%; padding: 0.5rem;
    font-weight: bold; outline: none; transition: border-color 0.3s;
}
.title-container input:focus { border-bottom: 1px solid #0066cc; color: var(--ui-text); }

/* Status Bar */
.status-bar {
    width: 100%; height: 16px; background-color: transparent;
    transition: background-color 0.3s; flex-shrink: 0; margin-top: 0.5rem;
}

/* Timer Display */
.timer-container {
    flex-grow: 1; display: flex; flex-direction: column;
    justify-content: center; align-items: center; width: 100%; padding: 0 2vw;
}

.timer-text {
    font-family: 'DSEG7', monospace;
    font-weight: bold; /* フォント定義と合わせる */
    /* 修正: 文字サイズと行間を調整してアーティファクトを防ぐ */
    font-size: min(22vw, 35vh);
    line-height: 1.2; /* 余裕を持たせる */
    padding-top: 1vh; /* 上部の欠け防止 */
    color: var(--text-default);
    transition: color 0.3s ease, opacity 0.3s ease, font-size 0.3s ease;
    text-align: center; width: 100%; white-space: nowrap;
    
    /* 描画最適化 */
    transform: translateZ(0);
    will-change: content; 
}
.timer-text.long-text { font-size: min(13vw, 22vh); }
.timer-text.dimmed { opacity: 0.6; }

.overtime-container {
    margin-top: 2vh; /* 間隔調整 */
    display: flex; align-items: center;
    justify-content: center; color: var(--c-red-ud);
    transition: opacity 0.3s ease;
}
.overtime-container.hidden { visibility: hidden; opacity: 0; }
.plus-mark { font-size: 5vw; margin-right: 1vw; font-weight: bold; }
.overtime-text { font-family: 'DSEG7', monospace; font-weight: bold; font-size: 14vw; line-height: 1.1; }

/* Control Panel */
.control-panel {
    background-color: var(--ui-bg);
    display: flex; flex-direction: column;
    border-top: 1px solid var(--ui-border);
    z-index: 10; padding: 0.5rem 1rem;
    gap: 0.5rem;
}

.panel-row { display: flex; align-items: center; justify-content: center; gap: 1rem; width: 100%; }

/* Input Row */
.input-row { justify-content: center; padding-bottom: 0.5rem; border-bottom: 1px solid rgba(128,128,128,0.2); }

.time-setting-group {
    display: flex; flex-direction: column; align-items: center;
    padding: 4px 10px; border-radius: 4px; border: 1px solid transparent;
}
.current-group { border-color: var(--current-border); background: rgba(0, 102, 204, 0.1); }
.next-group { border-color: var(--next-border); border-style: dashed; }

.setting-label { font-size: 0.7rem; font-weight: bold; color: #888; margin-bottom: 4px; letter-spacing: 1px;}
.time-inputs { display: flex; align-items: center; gap: 2px; }

.time-inputs input {
    width: 65px; padding: 4px; text-align: center;
    background: var(--input-bg); color: var(--ui-text);
    border: 1px solid var(--input-border);
    font-size: 1.1rem; border-radius: 4px; font-family: 'DSEG7', monospace;
}
.time-inputs input:disabled { opacity: 0.5; background: #222; cursor: not-allowed; }
.colon { font-weight: bold; color: #888; margin: 0 2px; }
.arrow-icon { font-size: 1.2rem; color: #888; }

/* Button Row */
.button-row { justify-content: space-between; padding-top: 0.2rem;}
.btn-group-main { display: flex; gap: 0.5rem; }
.btn-group-sub { display: flex; gap: 0.5rem; }

.control-btn {
    background-color: var(--btn-bg); color: #fff; border: none;
    padding: 8px 16px; font-size: 0.9rem; cursor: pointer;
    border-radius: 4px; font-weight: bold; white-space: nowrap;
    transition: background-color 0.2s;
}
.control-btn:hover:not(:disabled) { opacity: 0.8; }
.control-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.bell-btn { color: #ffd700; }
.theme-btn { padding: 8px 12px; }

/* Modal Styles */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex; justify-content: center; align-items: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--modal-bg); color: var(--ui-text);
    padding: 2rem; border-radius: 8px; border: 1px solid var(--ui-border);
    min-width: 600px; max-width: 95vw; max-height: 95vh;
    overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.modal-content h2 { text-align: center; margin-bottom: 1rem; font-size: 1.4rem; }
.setting-section h3 { font-size: 0.8rem; color: #888; margin-bottom: 0.5rem; border-bottom: 1px solid #444; padding-bottom: 4px; }
.input-group { display: flex; gap: 1rem; justify-content: center; margin-bottom: 1.5rem; }
.input-item { display: flex; flex-direction: column; align-items: center; }
.input-item label { font-size: 0.7rem; margin-bottom: 4px; color: #888; }
.input-item input { font-size: 1.5rem; width: 80px; text-align: center; font-family: 'DSEG7'; background: var(--input-bg); color: var(--ui-text); border: 1px solid var(--input-border); padding: 4px; }
.toggle-group { display: flex; gap: 2rem; justify-content: center; margin-top: 0.5rem; margin-bottom: 1.5rem;}
.toggle-group label { cursor: pointer; display: flex; align-items: center; gap: 0.5rem;}
.tabs { display: flex; border-bottom: 1px solid #555; margin-bottom: 1rem; }
.tab-btn { background: none; border: none; color: #888; padding: 0.5rem 1rem; cursor: pointer; font-weight: bold; border-bottom: 3px solid transparent; }
.tab-btn.active { color: var(--ui-text); border-bottom-color: #0066cc; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.phase-row { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 0.8rem; background: rgba(128,128,128,0.1); padding: 0.8rem; border-radius: 6px; border: 1px solid rgba(128,128,128,0.2); }
.phase-info { width: 170px; flex-shrink: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.phase-label { font-weight: bold; font-size: 0.9rem; }
.phase-desc { font-size: 0.8rem; color: #888; }
.phase-time-input { display: flex; align-items: center; gap: 2px; }
.phase-time-input label { font-size: 0.7rem; color: #888; margin-right: 4px;}
.tiny-input { width: 36px; padding: 4px 2px; text-align: center; background: var(--input-bg); color: var(--ui-text); border: 1px solid var(--input-border); font-size: 0.9rem; }
.palette-container { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.color-option { position: relative; cursor: pointer; }
.color-option input { position: absolute; opacity: 0; cursor: pointer; }
.swatch { display: block; width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 2px rgba(0,0,0,0.5); transition: transform 0.1s, border-color 0.2s; }
.color-option input:checked + .swatch { transform: scale(1.1); border-color: #fff; box-shadow: 0 0 0 2px #0066cc; }
.swatch.default { background: #888; background-image: linear-gradient(45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%); border: 1px solid #666; }
.swatch.red { background: var(--c-red); }
.swatch.red-ud { background: var(--c-red-ud); }
.swatch.yellow { background: var(--c-yellow); }
.swatch.yellow-ud { background: var(--c-yellow-ud); }
.swatch.green { background: var(--c-green); }
.swatch.green-ud { background: var(--c-green-ud); }
.blink-check { font-size: 0.8rem; display: flex; align-items: center; gap: 4px; margin-top: 4px; cursor: pointer; }
.modal-actions { display: flex; justify-content: center; gap: 1rem; margin-top: 2rem; }
.modal-btn { padding: 12px 24px; cursor: pointer; border-radius: 4px; border: none; font-weight: bold;}
.modal-btn.primary { background: #0066cc; color: #fff; }
.error-message { color: var(--c-red-ud); text-align: center; background: rgba(255,0,0,0.1); padding: 0.5rem; margin-bottom: 1rem; border: 1px solid var(--c-red-ud); }
.error-message.hidden { display: none; }
.blink { animation: flash 1s infinite; }
@keyframes flash { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }