/* 今天吃什么 — 前台样式（还原原站手感 + 移动优先） */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

html { font-size: 14px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
                 "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    background: #E8DACF;
    color: #333;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

/* ---------------------------------------------------------- 背景 */

/* 背景图（老板提供的图 B，已压成 WebP，原图 2.52MB → 32KB）
   实测：平均亮度 215、反差 stddev 24（偏浅柔和）
   底色取图片主色 #E8DACF，图片未加载完时不会闪一层灰。 */
.bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-color: #E8DACF;
    background-image: url('/static/img/bg-b.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 给图片盖一层白纱 0.28：照片有明暗细节，直接放文字会“花纹吃字”。
   🔴 这个值和图 A（0.52）不同。图 B 本来就浅，鲉太厚会糊成一块死白。 */
.bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, .28);
}

/* 宽屏用 1920 宽（WebP 32KB） */
@media (min-width: 900px) {
    .bg { background-image: url('/static/img/bg-b.webp'); }
}

/* 窄屏用 1080 宽的小图（11KB），省流量
   🔴 手机竖屏 cover 只从横图里裁一条 9:16 窄带（≈26% 宽度）。
   实测这条带居中细节值 14.7、靠右 29.3 → 靠右才不显得空。 */
@media (max-width: 899px) {
    .bg {
        background-image: url('/static/img/bg-b-sm.webp');
        background-position: 88% center;
    }
}

/* ---------------------------------------------------------- 主体 */

#wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    width: 90%;
    max-width: 640px;
    text-align: center;
    transform: translate3d(-50%, -70%, 0);
}

.title {
    margin: 0 0 30px;
    padding: 0;
    font-weight: 400;
    font-size: 32px;
    line-height: 1.35;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color .2s;
}

.title .what {
    font-weight: 700;
    color: #111;
}

.title .period-label {
    color: #00BDD6;
    font-weight: 600;
}

.title.shake { animation: shake .4s; }

#start {
    display: inline-block;
    padding: 5px;
    border: 0;
    background: rgba(0, 0, 0, .1);
    border-radius: 40px;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, .07), 0 1px rgba(255, 255, 255, .5);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

#start > span {
    display: block;
    width: 180px;
    height: 60px;
    line-height: 60px;
    border-radius: 35px;
    font-size: 32px;
    color: #fff;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
    border: 1px solid #E88E1D;
    background: linear-gradient(to bottom, #FFBA30, #FF911E);
    box-shadow: inset 0 1px #FFD17C, 0 2px 3px rgba(0, 0, 0, .2);
    transition: background .12s, box-shadow .12s;
}

#start:hover > span {
    background: linear-gradient(to bottom, #FFCE44, #FFA532);
    box-shadow: inset 0 1px #FFE696, 0 2px 3px rgba(0, 0, 0, .2);
}

#start:active > span {
    background: linear-gradient(to bottom, #FF911E, #FFBB30);
    box-shadow: inset 0 1px #FFB050, 0 2px 3px rgba(0, 0, 0, .2);
}

#start:focus-visible { outline: 2px solid #00BDD6; outline-offset: 3px; }

.os {
    position: absolute;
    top: 100%;
    left: 50%;
    width: 80%;
    margin: 0;
    transform: translate3d(-50%, 50px, 0);
    color: #4A4A4A;
    font-size: 14px;
    line-height: 1.4;
    min-height: 20px;
    transition: opacity .25s;
}

/* 饭点提示气泡 */
.tip {
    position: absolute;
    top: -50px;
    left: 50%;
    display: block;
    padding: 7px 12px;
    border-radius: 15px;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: 13px;
    white-space: nowrap;
    transform: translate3d(-50%, 0, 0);
    animation: dinnerTip 3s 1s linear both;
    pointer-events: none;
}

.tip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -4px;
    border: 8px solid transparent;
    border-top-color: rgba(0, 0, 0, .6);
}

/* ---------------------------------------------------------- 飘字容器 */

#temp-container {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    pointer-events: none;
}

#temp-container .temp {
    position: absolute;
    /* 🔴 原为 #777：纯灰底时够用，挂上照片背景后实测只有 3.3~3.6:1，偏淡 */
    color: #4E4E4E;
    white-space: nowrap;
    animation: flash 1.6s ease-out both;
    will-change: transform, opacity;
}

/* ---------------------------------------------------------- 模式切换 */

#toggle {
    position: absolute;
    bottom: 60px;
    left: 50%;
    z-index: 4;
    /* 🔴 必须是 flex：两个 span 写成两行时，inline-block 之间会产生
       约 3.8px 的换行空白，而 .hb 用的是硬编码 left:70px，
       导致切到「非正常人类」时蓝块整体左移几像素。
       flex 会忽略纯空白文本节点，彻底消除这个间隙。 */
    display: flex;
    align-items: center;
    padding: 2px;
    border-radius: 20px;
    background: rgba(255, 255, 255, .6);
    font-size: 12px;
    transform: translateX(-50%);
    transition: transform .3s, opacity .3s;
}

#toggle > span {
    position: relative;
    z-index: 2;
    display: inline-block;
    padding: 5px 10px;
    /* 🔴 原为 #999：照片+胶囊双层白底上实测仅 2.3~2.6:1，小字发灰看不清 */
    color: #4A4A4A;
    line-height: 1;
    cursor: pointer;
    transition: color .3s;
}

#toggle > span.selected { color: #fff; }

#toggle .hb {
    position: absolute;
    top: 2px;
    left: 2px;
    z-index: 1;
    /* 🔴 box-sizing 必须是 content-box：全局用了 border-box，
       而这里 width/height 是按「文字尺寸」算的（4em 宽 / 1em 高），
       内边距 5px 10px 是额外撑开的。用 border-box 会把 padding 吃掉，
       导致色块只有 12px 高、文字 22px 高 —— 上半截蓝、下半截白。 */
    box-sizing: content-box;
    width: 4em;
    height: 1em;
    padding: 5px 10px;
    border-radius: 20px;
    background: #00BDD6;
    transition: left .3s, width .3s, background-color .3s;
}

#toggle > span[data-mode="weird"].selected ~ .hb {
    left: 70px;
    width: 5em;
    background-color: #E80773;
}

body.playing #toggle {
    transform: translateX(-50%) translateY(200%);
    opacity: 0;
}

/* ---------------------------------------------------------- 吐槽弹窗 */

.comment {
    position: absolute;
    bottom: 60px;
    left: 50%;
    z-index: 5;
    padding: 5px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, .3);
    color: #fff;
    font-size: 14px;
    white-space: nowrap;
    transform: translateX(-50%);
    animation: comment 3s both;
    pointer-events: none;
}

/* ---------------------------------------------------------- 页脚 */

.foot {
    position: absolute;
    bottom: 18px;
    left: 50%;
    z-index: 4;
    transform: translateX(-50%);
    font-size: 11px;
    /* 🔴 原来 opacity .55 + #666，叠起来等于 #A6A6A6，照片上只有 2:1
       改为直接给够深的本色，不再压 opacity */
    opacity: .9;
    transition: opacity .3s;
}

.foot a {
    color: #4A4A4A;
    text-decoration: none;
    padding: 6px 10px;
}

.foot a:hover { opacity: .8; }

body.playing .foot { opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------- 动画 */

@keyframes flash {
    0%   { opacity: 0; transform: scale(1.5); color: transparent; text-shadow: 0 0 5px rgba(0, 0, 0, .5); }
    50%  { opacity: 1; }
    100% { opacity: 0; transform: scale(.5); }
}

@keyframes shake {
    0%   { transform: translateX(5px); }
    20%  { transform: translateX(-10px); }
    40%  { transform: translateX(15px); }
    60%  { transform: translateX(-20px); }
    80%  { transform: translateX(15px); }
    100% { transform: translateX(-10px); }
}

@keyframes comment {
    0%, 100% { opacity: 0; transform: translate3d(-50%, 200%, 0) scale(.7); }
    20%, 80% { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1); }
}

@keyframes dinnerTip {
    0%, 100% {
        opacity: 0;
        transform: perspective(600px) translate3d(-50%, 7px, 0) scale(.7) rotateY(180deg);
    }
    20%, 80% {
        opacity: 1;
        transform: perspective(600px) translate3d(-50%, 0, 0) scale(1) rotateY(0deg);
    }
}

/* ---------------------------------------------------------- 移动端 */

@media (max-width: 480px) {
    .title { font-size: 26px; margin-bottom: 26px; }
    #start > span { width: 156px; height: 54px; line-height: 54px; font-size: 28px; }
    #wrapper { transform: translate3d(-50%, -62%, 0); }
    #toggle { bottom: 48px; }
    .foot { bottom: 10px; }
}

@media (max-width: 360px) {
    .title { font-size: 22px; }
    #start > span { width: 140px; height: 50px; line-height: 50px; font-size: 25px; }
}

/* 尊重「减少动态效果」偏好：关掉满屏飘字与抖动 */
@media (prefers-reduced-motion: reduce) {
    #temp-container .temp { display: none; }
    .title.shake { animation: none; }
    .tip { animation: none; opacity: 1; }
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------- 记录按钮 */

#history-btn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 6;
    padding: 8px 14px;
    border: 0;
    border-radius: 20px;
    background: rgba(255, 255, 255, .82);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .1), inset 0 1px rgba(255, 255, 255, .8);
    color: #4A4A4A;
    font-family: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: background .2s, color .2s, transform .2s;
}

#history-btn:hover { background: rgba(255, 255, 255, .95); color: #222; }
#history-btn:active { transform: scale(.95); }
#history-btn:focus-visible { outline: 2px solid #00BDD6; outline-offset: 3px; }

/* 面板展开时按钮变深色，提示可以再点收回 */
#history-btn[aria-expanded="true"] {
    background: #00BDD6;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 189, 214, .4);
}

body.playing #history-btn {
    transform: translateY(200%);
    opacity: 0;
    pointer-events: none;
}

/* ---------------------------------------------------------- 记录面板 */

#history {
    position: absolute;
    inset: 0;
    z-index: 5;
    visibility: hidden;
    pointer-events: none;
}

#history.open {
    visibility: visible;
}

.history-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    max-height: 72%;
    padding: 14px 14px 0;
    border-radius: 18px 18px 0 0;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, .13);
    /* 默认整块藏到屏幕下沿之外 */
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.22, .61, .36, 1);
    will-change: transform;
    pointer-events: auto;
}

#history.open .history-panel {
    transform: translateY(0);
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding-bottom: 10px;
    border-bottom: 1px solid #EEEFF2;
}

.history-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.history-clear {
    padding: 4px 10px;
    border: 0;
    border-radius: 12px;
    background: #F2F3F5;
    color: #888;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}

.history-clear:hover { background: #EAECEF; color: #555; }
.history-clear:active { transform: scale(.96); }

.history-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 4px 0 10px;
}

.history-empty {
    margin: 26px 0;
    text-align: center;
    color: #AAA;
    font-size: 13px;
}

.history-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 9px 2px;
    border-bottom: 1px solid #F5F6F8;
    font-size: 14px;
}

.history-item:last-child { border-bottom: 0; }

.history-item .h-text {
    flex: 1 1 auto;
    color: #2B2F36;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item .h-meta {
    flex: 0 0 auto;
    font-size: 11px;
    color: #A8AEB8;
    font-variant-numeric: tabular-nums;
}

.history-item .h-weird {
    flex: 0 0 auto;
    padding: 1px 6px;
    border-radius: 10px;
    background: #FDEBF3;
    color: #D6336C;
    font-size: 10px;
}

.history-foot {
    flex: 0 0 auto;
    margin: 0;
    padding: 9px 0 calc(9px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #F5F6F8;
    text-align: center;
    color: #B4BAC3;
    font-size: 11px;
}

@media (max-width: 480px) {
    #history-btn { bottom: 44px; right: 12px; padding: 7px 12px; font-size: 12px; }
    .history-panel { max-height: 68%; }
}

/* 减少动态效果：面板直接就位，不做滑入 */
@media (prefers-reduced-motion: reduce) {
    .history-panel { transition: none; }
}
