/* リセット */
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
    display: block;
}

:root {
    --font-din: "Barlow Semi Condensed", "Helvetica Neue", Arial, sans-serif;
    --color-bg: #101139;
    --color-card: #1a1b4b;
    --color-border: #2a2c60;
    --color-accent: #ff6600;
}

body {
    line-height: 1;
    background-color: var(--color-bg);
    color: #ffffff;
    font-family: "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}
*,
*::before,
*::after {
    box-sizing: border-box;
}
button,
input,
select,
textarea {
    outline: none;
}

/* 共通フォント設定 */
.label,
.add-btn,
.val,
.unit,
.time {
    font-family: var(--font-din);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

.detailed-time {
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 11px;
    color: #a0a0b0;
    line-height: 1.4;
}
.detailed-time.right-align {
    text-align: right;
    margin-top: 4px;
}

/* ボタン類 */
.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}
.main-setting-btn {
    background: none;
    border: none;
    font-size: 12px;
    color: #aaa;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}
.main-setting-btn:hover {
    color: #fff;
}
.action-btn-group {
    display: flex;
    gap: 4px;
    align-items: center;
}
.icon-action-btn {
    width: 26px;
    height: 26px;
    background-color: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #aaa;
    transition: all 0.2s;
}
.icon-action-btn:hover {
    background-color: #3a3c70;
    color: #fff;
}

#app {
    display: none;
    flex-grow: 1;
    flex-direction: column;
}
#main-clock-area {
    padding: clamp(20px, 4vw, 40px) 0 0 0;
    display: flex;
    flex-direction: column;
}
.main-clock {
    width: 100%;
    text-align: left;
    padding: 0 clamp(20px, 4vw, 50px);
}
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5vw;
}

/* -------------------------------------------
   ニキシー管表示（JS不要のCSS 100%自動追従）
------------------------------------------- */
#main-time-wrapper {
    container-type: inline-size; /* 親枠として幅を監視 */
    width: 100%;
    margin: 1.5vw 0;
}
.nixie-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    width: 100%;
    margin: 0;
}

/* 微細な横幅の揺らぎ（99%へ縮んで戻る）アニメーション */
@keyframes nixie-jitter-width {
    0%,
    100% {
        transform: scaleX(1);
    }
    50% {
        transform: scaleX(0.99);
    }
}
.nixie-digit {
    background-image: url("img/nishiki.png");
    background-repeat: no-repeat;
    background-size: 1200% 100%;
    aspect-ratio: 200 / 490;
    width: 9cqw;
    height: auto;
    background-position: calc(var(--digit-index) * (100% / 11)) 0;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;

    /* ↓ 追加：管ひとつひとつの中心を軸にして、微小な揺らぎアニメーションを実行 */
    transform-origin: center center;
    animation: nixie-jitter-width 0.08s infinite linear;
}
/* ↓ 追加：管ごとに揺れの周期をわずかにズラして、独立した振動を表現する（超重要！） */
.nixie-digit:nth-child(even) {
    animation-duration: 0.07s;
}
.nixie-digit:nth-child(3n) {
    animation-duration: 0.09s;
}
.nixie-digit:nth-child(5n) {
    animation-duration: 0.06s;
}

.nixie-unit {
    font-size: 7cqw;
    font-weight: 300;
    color: #ffffff;
    margin: 0 0.5cqw 1cqw 0.5cqw;
    line-height: 1;

    /* 単位（h, m, s）も一緒に揺らす場合 */
    transform-origin: center center;
    animation: nixie-jitter-width 0.08s infinite linear;
}

/* ↓ 追加：99.5%の縮小と100%を繰り返す */
@keyframes nixie-jitter-width {
    0%,
    100% {
        transform: scaleX(1);
    }
    50% {
        transform: scaleX(0.99);
    }
}

/* 接触不良風のフリッカー演出（既存のまま） */
.nixie-flicker {
    animation: nixie-bad-contact 0.4s linear;
}
@keyframes nixie-bad-contact {
    0% {
        opacity: 1;
    }
    10% {
        opacity: 0.1;
    }
    15% {
        opacity: 0.9;
    }
    30% {
        opacity: 0.2;
    }
    40% {
        opacity: 0.8;
    }
    55% {
        opacity: 0.1;
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 1;
    }
}

.main-info-row {
    display: grid;
    grid-template-columns: 70% 28%;
    gap: 2%;
    margin-top: 2vw;
    padding-bottom: 2vw;
    border-bottom: 1px solid var(--color-border);
    align-items: start;
}
.main-info-left {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}
.life-stats {
    font-size: 11px;
    color: #a0a0b0;
}
.life-stats span {
    font-weight: bold;
    color: #ffffff;
}

/* -------------------------------------------
   【A案】統計ブロック（数字と単位 1:0.5）
------------------------------------------- */
.auto-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}
.auto-stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 15px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 90px;
}
.auto-stat-card .stat-label {
    font-size: 11px;
    color: #a0a0b0;
    margin-bottom: 8px;
    font-weight: bold;
}
.stat-value {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    overflow: hidden;
}

/* 1行に収まるようにJSでスケール制御されるラッパー */
.stat-text-scaler {
    display: flex;
    align-items: baseline;
    white-space: nowrap;
    transform-origin: center center;
}
.stat-text-scaler .val {
    font-size: 26px;
    font-weight: bold;
    color: #ffffff;
}
.stat-text-scaler .unit {
    font-size: 13px;
    font-weight: 300;
    color: #ffffff;
    margin: 0 4px 0 2px;
}

/* -------------------------------------------
   右側計算ブロック（JS不要のCSS 100%自動追従）
------------------------------------------- */
.main-info-right {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.calc-clocks {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.calc-clock-block {
    background: var(--color-card);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
}
.calc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.calc-header .label {
    font-size: 12px;
    font-weight: bold;
    color: #ffffff;
}

.calc-time-wrapper {
    container-type: inline-size; /* 親枠として幅を監視 */
    width: 100%;
    display: flex;
    justify-content: flex-end;
}
.calc-time {
    display: flex;
    align-items: baseline;
    white-space: nowrap;
    color: #ffffff;
}
.calc-time.sleep-time {
    color: #4a90e2;
}

/* 幅に合わせて数字と単位（1:0.5）が自動スケール */
.calc-time .val {
    font-size: 11.5cqw;
    font-weight: bold;
    line-height: 1;
}
.calc-time .unit {
    font-size: 5.75cqw;
    font-weight: 300;
    margin: 0 0.5cqw 0 0.2cqw;
    line-height: 1;
}

/* -------------------------------------------
   サブ時計
------------------------------------------- */
.add-clock-wrapper {
    padding: 20px clamp(20px, 4vw, 50px);
    text-align: left;
}
.add-btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: bold;
    border: 2px dashed #ffffff;
    background: transparent;
    color: #ffffff;
    cursor: pointer;
    border-radius: 4px;
}
.add-btn:hover {
    background: #ffffff;
    color: var(--color-bg);
    border-style: solid;
}

#sub-clocks-wrapper {
    width: 100%;
    padding: 20px clamp(20px, 4vw, 50px);
}
#sub-clocks {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
}
.sub-clock-block {
    position: relative;
    width: calc(33.333% - 14px);
    min-width: 280px;
    padding: 16px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
}
.sub-clock-block.is-locked {
    opacity: 0.85;
    background-color: #141530;
}
.sub-clock-block .label {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 12px;
    color: #ffffff;
    padding-right: 90px;
}
.sub-clock-block .time-wrapper {
    position: relative;
    padding-bottom: 6px;
    margin-bottom: 6px;
}

/* サブ時計の数字も1:0.5比率 */
.sub-clock-block .time {
    display: flex;
    align-items: baseline;
    color: #ffffff;
}
.sub-clock-block .time .val {
    font-size: 28px;
    font-weight: bold;
}
.sub-clock-block .time .unit {
    font-size: 14px;
    font-weight: 300;
    margin: 0 4px 0 2px;
}

.gauge-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}
.gauge-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background-color: var(--color-accent) !important;
    box-shadow: 0 0 8px var(--color-accent);
    border-radius: 2px;
    transition: width 1s linear;
}

/* モーダル・タイムライン等 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(16, 17, 57, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-overlay.active {
    display: flex;
}
.modal-content {
    background: var(--color-card);
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    color: #ffffff;
    border: 1px solid var(--color-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.modal-content h2 {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 10px;
}
.form-group {
    margin-bottom: 15px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 8px;
    color: #aaa;
}
input[type="date"],
input[type="datetime-local"],
input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: #ffffff;
}
.modal-btns {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
}
.btn-primary {
    background: var(--color-accent);
    color: #ffffff;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}
.btn-primary:hover {
    background: #e65c00;
}
.btn-white {
    background: transparent;
    color: #ffffff;
    border: 1px solid #ffffff;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
}
.day-checkboxes {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.day-checkboxes label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
}
.timeline-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 6px;
}
.timeline-container {
    position: relative;
    min-width: 500px;
    height: 50px;
    user-select: none;
}
.timeline-bg-line {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
}
.timeline-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
}
.tl-dot-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.tl-dot {
    width: 20px;
    height: 20px;
    background: var(--color-card);
    border: 2px solid #555;
    border-radius: 50%;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    transition: all 0.1s;
    color: #aaa;
}
.tl-dot:hover {
    transform: scale(1.2);
    border-color: #fff;
    color: #fff;
}
.tl-dot.sleep {
    background-color: #4a90e2;
    border-color: #4a90e2;
    color: #fff;
}
.tl-dot.work {
    background-color: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}
.clear-btn {
    background: none;
    border: 1px solid #555;
    color: #aaa;
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
}

@media (max-width: 1024px) {
    .main-info-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}
@media (max-width: 768px) {
    .auto-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    #sub-clocks-wrapper {
        padding: 15px 0;
        overflow: hidden;
    }
    #sub-clocks {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        gap: 0;
        padding: 0 15px;
    }
    #sub-clocks::-webkit-scrollbar {
        display: none;
    }
    .sub-clock-block {
        flex: 0 0 calc(100% - 10px);
        margin: 0 5px;
        scroll-snap-align: center;
    }

    /* スマホ時は統計の基本フォントを少し下げる */
    .stat-text-scaler .val {
        font-size: 20px;
    }
    .stat-text-scaler .unit {
        font-size: 10px;
    }
}
.slider-dots {
    display: none;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}
@media (max-width: 768px) {
    .slider-dots {
        display: flex;
    }
}
.slider-dot {
    width: 8px;
    height: 8px;
    background: #555;
    border-radius: 50%;
    transition: background 0.3s;
}
.slider-dot.active {
    background: var(--color-accent);
}
