/* ============================================================
   计时模块统一样式（创建房间弹窗 + 悬浮计时组件）
   各类棋类游戏通过引入此 CSS 即可获得统一外观。
   ============================================================ */

/* ---------- 通用：计时模式选择 / 详细设置弹窗 ---------- */

.timer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 26, 0.16);
    backdrop-filter: blur(1.5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
}

.timer-modal.hidden {
    display: none;
}

.timer-modal__content {
    background: linear-gradient(180deg, rgba(244, 242, 237, 0.96), rgba(250, 249, 246, 0.96));
    padding: 1.7rem 1.8rem 1.5rem;
    border-radius: 22px;
    border: 1px solid rgba(201, 169, 98, 0.22);
    box-shadow: 0 30px 60px rgba(26, 26, 26, 0.18);
    text-align: center;
    width: min(92vw, 420px);
    position: relative;
    backdrop-filter: blur(6px);
}

.timer-modal__content::before {
    content: '';
    position: absolute;
    inset: 12px;
    border: 1px solid rgba(201, 169, 98, 0.08);
    border-radius: 16px;
    pointer-events: none;
}

.timer-modal__title {
    margin: 0 0 0.4rem;
    color: var(--deep-charcoal, #1a1a1a);
    letter-spacing: 0.12em;
    font-size: 1.2rem;
    font-weight: 600;
}

.timer-modal__subtitle {
    margin: 0 0 1.2rem;
    color: var(--muted, #8c8880);
    font-size: 0.86rem;
    letter-spacing: 0.06em;
}

/* 一组按钮（自由 / 限时；包干 / 加秒 / 读秒） */
.timer-modal__options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    margin-bottom: 1.1rem;
}

.timer-modal__options.timer-modal__options--three {
    grid-template-columns: repeat(3, 1fr);
}

.timer-option-btn {
    appearance: none;
    border: 1px solid rgba(201, 169, 98, 0.28);
    background: rgba(255, 255, 255, 0.78);
    color: var(--deep-charcoal, #1a1a1a);
    padding: 0.85rem 0.6rem;
    border-radius: 14px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    transition: transform 0.2s ease, box-shadow 0.2s ease,
                border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
    font-family: inherit;
}

.timer-option-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(201, 169, 98, 0.6);
    box-shadow: 0 10px 22px rgba(26, 26, 26, 0.08);
}

.timer-option-btn.is-active {
    background: linear-gradient(135deg, var(--gold, #c9a962), var(--gold-warm, #b8956b));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 12px 24px rgba(184, 149, 107, 0.28);
}

.timer-option-btn__title {
    display: block;
    font-size: 0.98rem;
    font-weight: 700;
    margin-bottom: 0.18rem;
}

.timer-option-btn__desc {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--muted, #8c8880);
}

.timer-option-btn.is-active .timer-option-btn__desc {
    color: rgba(255, 255, 255, 0.86);
}

/* 输入字段 */
.timer-modal__fields {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    margin: 0.3rem 0 1.2rem;
    text-align: left;
}

.timer-modal__fields.hidden {
    display: none;
}

.timer-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid rgba(201, 169, 98, 0.22);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
}

.timer-field__label {
    flex: 1;
    color: var(--deep-charcoal, #1a1a1a);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.timer-field__hint {
    display: block;
    margin-top: 0.18rem;
    font-size: 0.7rem;
    color: var(--muted, #8c8880);
    font-weight: 500;
    letter-spacing: 0.04em;
}

.timer-field__input {
    width: 90px;
    min-height: 36px;
    border: 1px solid rgba(201, 169, 98, 0.32);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    background: #fff;
    color: var(--deep-charcoal, #1a1a1a);
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.timer-field__input:focus {
    outline: none;
    border-color: rgba(201, 169, 98, 0.7);
    box-shadow: 0 0 0 3px rgba(201, 169, 98, 0.16);
}

.timer-field__unit {
    font-size: 0.78rem;
    color: var(--muted, #8c8880);
    letter-spacing: 0.04em;
    min-width: 1.4rem;
    text-align: left;
}

/* 弹窗按钮区 */
.timer-modal__actions {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    margin-top: 0.6rem;
}

.timer-modal__btn {
    appearance: none;
    border: 1px solid transparent;
    cursor: pointer;
    min-height: 44px;
    padding: 0.6rem 1.4rem;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    font-family: inherit;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.timer-modal__btn--primary {
    background: linear-gradient(135deg, var(--gold, #c9a962), var(--gold-warm, #b8956b));
    color: #fff;
}

.timer-modal__btn--ghost {
    background: rgba(46, 46, 46, 0.06);
    color: var(--deep-charcoal, #1a1a1a);
}

.timer-modal__btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(26, 26, 26, 0.12);
}

.timer-modal__btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.timer-modal__error {
    margin: 0.4rem 0 0.6rem;
    min-height: 1.1rem;
    color: var(--action-danger, #a24c3c);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
}

/* 三级弹窗 - 返回按钮 */
.timer-modal__back {
    position: absolute;
    top: 0.9rem;
    left: 1rem;
    background: transparent;
    border: none;
    color: var(--muted, #8c8880);
    cursor: pointer;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    padding: 0.25rem 0.4rem;
    border-radius: 8px;
    font-family: inherit;
    transition: color 0.2s ease, background 0.2s ease;
}

.timer-modal__back:hover {
    color: var(--deep-charcoal, #1a1a1a);
    background: rgba(201, 169, 98, 0.12);
}

/* ============================================================
   悬浮计时组件（可拖拽小部件）
   ============================================================ */

.timer-widget {
    --timer-widget-bg: linear-gradient(180deg, rgba(34, 28, 22, 0.92), rgba(46, 38, 30, 0.92));
    --timer-widget-text: #fff7eb;
    --timer-widget-border: rgba(244, 242, 237, 0.18);
    --timer-widget-accent: rgba(201, 169, 98, 0.85);
    --timer-widget-danger: #e88275;

    position: absolute;
    z-index: 90;
    user-select: none;
    min-width: 200px;
    max-width: 260px;
    color: var(--timer-widget-text);
    background: var(--timer-widget-bg);
    border: 1px solid var(--timer-widget-border);
    border-radius: 16px;
    box-shadow: 0 18px 36px rgba(26, 26, 26, 0.22);
    backdrop-filter: blur(6px);
    font-family: inherit;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.timer-widget.hidden {
    display: none;
}

.timer-widget.is-dragging {
    box-shadow: 0 22px 44px rgba(26, 26, 26, 0.32);
    cursor: grabbing;
}

.timer-widget__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    cursor: grab;
    background: rgba(0, 0, 0, 0.18);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.timer-widget.is-dragging .timer-widget__header {
    cursor: grabbing;
}

.timer-widget__handle {
    width: 22px;
    height: 12px;
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 0 0 auto;
}

.timer-widget__handle::before,
.timer-widget__handle::after {
    content: '';
    display: block;
    height: 2px;
    background: rgba(255, 255, 255, 0.32);
    border-radius: 2px;
}

.timer-widget__handle span {
    display: block;
    height: 2px;
    background: rgba(255, 255, 255, 0.32);
    border-radius: 2px;
}

.timer-widget__title {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 247, 235, 0.8);
}

.timer-widget__mode {
    flex: 0 0 auto;
    font-size: 0.7rem;
    padding: 0.15rem 0.55rem;
    border: 1px solid var(--timer-widget-accent);
    border-radius: 999px;
    color: var(--timer-widget-accent);
    letter-spacing: 0.08em;
    background: rgba(201, 169, 98, 0.08);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.timer-widget__mode:hover {
    background: rgba(201, 169, 98, 0.2);
    color: #fff7eb;
}

/* 规则弹窗（挂载到 body，避免被 timer-widget overflow:hidden 裁剪） */
.timer-widget__rule-popup {
    z-index: 100000;
    padding: 0.5rem 0.75rem;
    background: rgba(30, 28, 24, 0.97);
    border: 1px solid rgba(201, 169, 98, 0.35);
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff7eb;
    white-space: nowrap;
    letter-spacing: 0.04em;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    animation: timer-popup-in 0.15s ease;
}

@keyframes timer-popup-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.timer-widget__body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.7rem 0.85rem 0.85rem;
}

.timer-widget__row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.timer-widget__row.is-active {
    background: rgba(201, 169, 98, 0.18);
    border-color: rgba(201, 169, 98, 0.42);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* "我"角标：绝对定位在行右上角，不挤占倒计时宽度 */
.timer-widget__row.is-self::after {
    content: '我';
    position: absolute;
    top: -0.4rem;
    right: -0.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 50%;
    background: linear-gradient(180deg, rgba(255, 252, 244, 0.98), rgba(231, 211, 164, 0.96));
    color: #4a3a1f;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    z-index: 2;
}

.timer-widget__row.is-warning .timer-widget__time {
    color: var(--timer-widget-danger);
}

.timer-widget__color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 auto;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.timer-widget__color-dot[data-color="black"] {
    background: #1a1a1a;
}

.timer-widget__color-dot[data-color="white"] {
    background: #fffdf8;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.timer-widget__color-dot[data-color="red"] {
    background: linear-gradient(180deg, #c55243 0%, #a33326 100%);
}

.timer-widget__color-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: rgba(255, 247, 235, 0.78);
}

.timer-widget__time {
    flex: 0 0 auto;
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    color: #fff7eb;
}

.timer-widget__byoyomi {
    flex: 0 0 auto;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: rgba(255, 247, 235, 0.64);
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.timer-widget__byoyomi.is-active {
    color: #fff7eb;
    background: rgba(232, 130, 117, 0.32);
}

.timer-widget__footer {
    padding: 0 0.85rem 0.7rem;
    font-size: 0.7rem;
    color: rgba(255, 247, 235, 0.5);
    letter-spacing: 0.04em;
    text-align: center;
}

/* ---------- 默认嵌入位置：PC 左侧栏 / 移动端 room-info 区域 ---------- */

.timer-widget.timer-widget--embedded {
    position: relative;
    z-index: auto;
    margin: 0 auto;
    width: 100%;
    max-width: 280px;
    box-shadow: 0 10px 24px rgba(26, 26, 26, 0.16);
}

/* 适配窄屏：宽度更紧凑、字号更小 */
@media (max-width: 1178px) {
    .timer-widget {
        min-width: 180px;
        max-width: 260px;
    }

    .timer-widget__time {
        font-size: 0.95rem;
    }
}

@media (max-width: 768px) {
    .timer-modal__content {
        padding: 1.3rem 1.2rem 1.1rem;
    }

    .timer-modal__options.timer-modal__options--three {
        grid-template-columns: 1fr;
    }

    .timer-widget {
        min-width: 160px;
    }

    .timer-widget__title {
        font-size: 0.72rem;
        letter-spacing: 0.08em;
    }

    .timer-widget__time {
        font-size: 0.92rem;
    }
}
