:root {
    --page-max: 1080px;
    --space: clamp(10px, 2vw, 20px);
    --clock-ratio: 3 / 1;
    --energy-ratio: 13 / 1;
    --answer-ratio: 3.1 / 1;
    --yellow: #ffd236;
}

html, body {
    margin: 0px;
}

body {
    font-family: "Noto Sans TC", system-ui, -apple-system, "Segoe UI", Roboto, Arial;
    color: rgb(255, 255, 255);
    background: url("../img/bg_quiz.png") center center / auto repeat, radial-gradient(120% 140% at 10% -10%, rgb(107, 210, 160) 0%, rgb(154, 216, 168) 35%, rgb(75, 126, 111) 100%);
    position: relative;
    /* text-wrap: balance; */
}

.hud {
    width: min(var(--page-max), 96vw);
    margin: calc(var(--space)) auto 0;
    display: flex;
    gap: var(--space);
    align-items: center;
    padding-top: 5px;
}

.clock {
    flex: 0 1 20%;
    aspect-ratio: var(--clock-ratio);
    background: url("../img/quiz_time.png") center center / contain no-repeat;
    position: relative;
}

.clock-text {
    position: absolute;
    inset: 0px 0px 0px 15%;
    display: grid;
    place-items: center;
    font-weight: 900;
    letter-spacing: 1px;
    font-size: clamp(14px, 2.6vw, 36px);
    color: rgb(58, 252, 195);
    text-shadow: rgb(8, 56, 51) 0px 2px 0px;
}

.clock .clock-text.is-danger {
  color: #FF000A; /* 倒數十秒時的紅色 */
}


.energy {
    flex: 1 1 80%;
    aspect-ratio: var(--energy-ratio);
    background: url("../img/quiz_score.png") left center / contain no-repeat;
    position: relative;
}

.energy-slots {
    position: absolute;
    inset: 18% 6% 18% 8%;
    display: flex;
    align-items: center;
}

.energy .cell {
    width: clamp(22px, 3.6vw, 41px);
    aspect-ratio: 1 / 1;
    background: url("../img/quiz_score_point.png") center center / contain no-repeat;
    display: inline-block;
    opacity: 0.25;                /* 預設半透明表示未啟用 */
    transform: scale(0.8);        /* 預設縮小一點 */
    transition: opacity 0.3s, transform 0.3s;
}

.energy .cell.is-on {
    opacity: 1;                   /* 亮起 */
    transform: scale(1);          /* 放大至正常大小 */
}

.stage {
    width: min(var(--page-max), 76vw);
    margin: calc(var(--space)) auto 0;
    display: flex;
    position: relative;
}

.title {
    position: absolute;
    top: 0%;
    left: 12%;
    transform: translateX(-50%);
    width: clamp(200px, 36vw, 384px);
    height: clamp(40px, 6vw, 101px);
    background: url("../img/quiz_title.png") center center / contain no-repeat;
    color: transparent;
    text-indent: -9999px;
    z-index: 50;
    margin: 0;
}

.board {
    background: rgba(18, 18, 18, 0.83);
    border: 3px solid var(--yellow);
    border-radius: 16px;
    padding: clamp(10px, 2vw, 27px);
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: clamp(12px, 2vw, 40px);
    box-shadow: rgba(126, 126, 126, 0.97) 0px 10px 20px;
    position: absolute;
    /* margin: 0 1% 0 5%; */
    width: min(78vw, 1080px);
}

.question {
    position: relative;
    margin-top: 18%;
    transform: translate(10%, 5%);
    background: rgb(91, 58, 39);
    color: rgb(255, 255, 255);
    border-radius: 16px;
    padding: clamp(12px, 2.2vw, 24px);
    box-shadow: rgba(0, 0, 0, 0.25) 0px 10px 20px inset;
    height: 44%;
    text-align: center;
    display: flex;
    align-items: center;
}

.qno {
    margin: 0px 0px 8px;
    font-size: clamp(18px, 3vw, 47px);
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(-28%, -65%); /* 可依實際視覺再微調 */
    font-style: italic;
    will-change: transform;
}

.qarea {
    position: absolute;
    margin-right: 20px;
}

.qtext {
    margin: 0px;
    font-size: clamp(14px, 3.4vw, 20px);
    line-height: 1.6;
    font-weight: 600;
}

/* === 題目附圖（只有帶 img 欄位的題目才顯示） === */
.qimg {
    margin: 0;
    display: none;
}

/* 題目框、外框尺寸完全不變：.qarea 維持絕對定位，圖片只排在文字下方 */
.question.has-qimg .qarea {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(6px, 1vw, 12px);
}

.question.has-qimg .qimg {
    display: block;
}

.qimg-pic {
    display: block;
    margin-inline: auto;   /* figure 寬度大於圖片時仍保持左右置中 */
    width: auto;
    height: auto;
    max-width: 72%;
    max-height: clamp(110px, 9.5vw, 180px);
    box-sizing: border-box;
    padding: clamp(3px, 0.5vw, 6px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.answers {
    display: grid;
    grid-auto-rows: 1fr;
    gap: clamp(12px, 1.8vw, 12px);
    align-content: start;
}

.answer {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: var(--answer-ratio);
    background: center center / contain no-repeat;
    border: 0px;
    cursor: pointer;
    color: rgb(255, 255, 255);
    padding: 0px;
    transition: transform 0.3s, box-shadow 0.3s;
    transform-origin: center center;
    overflow: visible;        /* 讓 tick 可外凸 */
    isolation: isolate; 
}

.answer:hover {
    transform: scale(1.05);
}

.badge {
    position: absolute;
    left: clamp(10px, 1.6vw, 18px);
    top: 50%;
    transform: translateY(-50%);
    width: clamp(32px, 3.4vw, 42px);
    aspect-ratio: 1 / 1;
    background-size: contain;
    background-position: center center;
    background-repeat: no-repeat;
    transition: filter 0.25s;
}

.badge-a {
    background-image: url("../img/quiz_a.png");
}

.badge-b {
    background-image: url("../img/quiz_b.png");
}

.badge-c {
    background-image: url("../img/quiz_c.png");
}

.badge-a, .badge-b, .badge-c {
    filter: brightness(0.6) grayscale(40%);
    transition: filter 0.25s;
}

.answer:hover.badge-a, .answer:hover.badge-b, .answer:hover.badge-c {
    filter: brightness(1) grayscale(0%);
}

.answer.badge-a.is-active, .answer.badge-b.is-active, .answer.badge-c.is-active {
    filter: brightness(1) grayscale(0%);
}

.testarea {
    display: flex;
    width: 77%;
    height: 100%;
    text-align: left;
    box-sizing: border-box;
    position: relative;
    margin-left: 12%;
    transform: translate(7%, 9%);
    padding-right: 7px;
    align-items: center;
}

.atext {
    font-size: clamp(12px, 1.2vw, 20px);
    padding: 0 50px 0 50px;
    word-break: break-word;
}

.tick {
    position: absolute;
    right: 10%;
    top: 70%;
    width: clamp(18px, 4vw, 60px);
    aspect-ratio: 1 / 1;
    background: url("../img/correct.png") center center / contain no-repeat;
    display: none;
}

.tick.error{
    background: url("../img/error.png") center center / contain no-repeat;
}


.answer.is-sate .tick {
    display: block;
}

.result-stage {
    margin: 0 10%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

.result-title {
    width: clamp(180px, 28vw, 430px);
    height: clamp(50px, 8vw, 90px);
    background: url("../img/result_title.png") center center / contain no-repeat;
    text-indent: -9999px;
    margin: 0px;
    top: -9%;
    left: -8%;
    z-index: 10;
    position: absolute;
}

.result-board {
    background: linear-gradient(rgba(0, 0, 0, 0.58) 0%, rgba(2, 1, 2, 0.61) 50%, rgba(96, 62, 94, 0.92) 100%);
    border: 3px solid var(--yellow);
    border-radius: 16px;
    padding: 75px clamp(20px, 3vw, 50px) clamp(20px, 3vw, 50px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 20px;
    box-shadow: rgba(0, 0, 0, 0.45) 0px 8px 20px;
    width: min(92vw, 1100px);
    height: clamp(323px, 40vh, 560px);
    position: relative;
    overflow: visible;
}

.grade {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.grade-title {
    position: absolute;
    left: 14%;
    top: -2%;
}

.grade-label {
    font-size: clamp(18px, 2vw, 28px);
    color: rgb(255, 255, 255);
    font-style: italic;
    font-weight: 700;
    letter-spacing: 5px;
}

.grade-icon {
    width: clamp(100px, 18vw, 225px);
    height: clamp(100px, 18vw, 225px);
}

.grade-icon.grade-b {
    background: url("../img/result_grade_b.png") center center / contain no-repeat;
}

.grade-icon.grade-a {
    background: url("../img/result_grade_a.png") center center / contain no-repeat;
}

.grade-icon.grade-s {
    background: url("../img/result_grade_s.png") center center / contain no-repeat;
}

.grade-text{
  color: #fff;
  margin: 0 10px 30px 10px;
  text-align: center;
  font-size: 1rem;
  /* background: rgb(255 220 0 / 16%); */
  padding: 10px;
  border-radius: 10px;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 88px;
    align-items: center;
    position: relative;
}

.stat-item {
    background: rgba(255, 220, 0, 0.4);
    border-radius: 12px;
    padding: 12px 20px;
    justify-content: space-between;
    width: 50%;
    position: relative;
}

.stat-label {
    font-size: clamp(16px, 1.8vw, 24px);
    color: rgb(255, 255, 255);
    position: absolute;
    top: -27px;
    left: -30px;
    font-weight: 700;
    letter-spacing: 5px;
    font-style: italic;
}

.stat-value-area {
    display: flex;
    justify-content: center;
}

.stat-value {
    font-size: clamp(28px, 3vw, 52px);
    font-weight: 700;
    color: rgb(255, 255, 255);
}

.btn-confirm {
    display: block;
    width: clamp(120px, 20vw, 140px);
    height: clamp(50px, 8vw, 70px);
    background: url("../img/quiz_result_btn_confirm.png") center center / contain no-repeat;
    border: none;
    color: rgb(0, 0, 0);
    font-weight: 700;
    font-size: clamp(16px, 2.8vw, 25px);
    cursor: pointer;
    letter-spacing: 2px;
    position: relative;
    bottom: clamp(8px, 2vw, 20px);
    right: clamp(8px, 2vw, 20px);
    transform: translate(18%, 96%);
    font-family: "Noto Sans TC", system-ui, -apple-system, "Segoe UI", Roboto, Arial;
    padding-bottom: 5px;
}

.btn-confirm:hover {
    transform: translate(18%, 92%);
    transition: transform 0.2s;
}

.btn-area {
    display: flex;
    justify-content: center;
}

.btn-area.result{
  gap: 10px;
  position: absolute;
  top: 85%;
  left: 74%;
}

.btn-area.next {
    position: absolute;
    bottom: clamp(0px, 2.2vw, 42px);   /* 數字越小按鈕越往下 */
    /* 水平對齊題目框中心：外框留白 +（內容寬 − 欄距）× 1.1/2.1 × 0.6
       0.6 = 欄中心 0.5 加上 .question 的 translateX(10%) */
    left: calc(clamp(10px, 2vw, 27px)
             + (100% - 2 * clamp(10px, 2vw, 27px) - clamp(12px, 2vw, 40px)) * 0.31428);
    right: auto;
    transform: translateX(-50%);
}

.btn-confirm.quiz-exit{
    bottom: 0;
    right: 0;
    transform: none;
}
.btn-confirm.quiz-exit:hover{
    transform: translate(-2%, -4%);
}

@media (max-width: 1470px) {
    .result-title {
        width: clamp(181px, 36vw, 442px);
        height: clamp(50px, 8vw, 99px);
    }

    .result-board {
        width: 90%;
    }
}

@media (max-width: 1200px) {
    .btn-area.result{
        left: 71%;
        top: 83%;
    }
}


@media (max-width: 967px) {
    .result-stage{
        margin: 0;
    }

    .hud {
        padding-bottom: 10px;
    }

    .stage {
        width: min(680px, 75vw);
    }

    .title {
        margin: 0 auto calc(var(--space) * 0.6);
        height: clamp(40px, 9vw, 101px);
        top: 1%;
    }

    .board {
        grid-template-columns: 1fr;
        gap: var(--space);
        display: flex;
        flex-direction: column;
        position: relative;
        margin: 20px;
    }

    .clock-text {
        font-size: clamp(14px, 3.6vw, 36px);
    }

    .energy .cell {
        width: clamp(22px, 4vw, 44px);
    }

    .question {
        width: 80%;
        transform: translate(7%, 5%);
    }

    /* 手機版外框為單欄直式，題目框改為隨圖片高度自動延展 */
    .question.has-qimg {
        height: auto;
    }

    .question.has-qimg .qarea {
        position: relative;
        margin-right: 0;
        width: 100%;
    }

    /* 直式排列時改用寬度主導，並在題目框內左右置中 */
    .qimg {
        width: 100%;
    }

    /* 手機版 figure 佔滿題目框寬度，圖片再取其 40% */
    .qimg-pic {
        max-width: 40%;
        max-height: 34vw;
    }

    .answers {
        margin: 10% 0px;
    }

    .qarea {
        display: contents;
    }


    .answer.is-sate .tick {
        width: clamp(18px, 9.2vw, 79px);
        right: 6%;
    }

    .atext {
        font-size: clamp(14px, 3.2vw, 20px);
    }

    :root {
        --answer-ratio: 2.9/ 1;
        --energy-ratio: 12 / 1;
    }

    .result-title {
        width: clamp(259px, 46vw, 442px);
        height: clamp(104px, 13vw, 99px);
    }

    .result-board {
        grid-template-columns: auto;
        min-height: 600px;
        width: 76%;
    }

    .btn-confirm {
        position: relative;
        margin: 3% 0px;
        bottom: 0px;
        right: 0px;
        transform: none;
    }

    .btn-confirm.result {
      position: relative;
      margin: 3% 0px;
      bottom: 0px;
      right: 0px;
      transform: none;
    }

    .grade {
        margin-top: 1.5rem;
    }

    .btn-area.next {
        right: 0px;
        position: relative;
        bottom: clamp(0px, 8vw, 61px);
        left: auto;            /* 取消桌機版的題目框置中定位 */
        transform: none;
    }

    .btn-area.result{
        position: relative;
        top: unset;
        left: unset;
    }

    .stats {
        gap: 50px;
    }

    .btn-confirm:hover {
        transform: translate(0%, -7%);
    }

    .tick{
        top: 82%;
        width: clamp(18px, 6vw, 60px);
    }

    .timeup-card{
        margin: 0 30px;
    }
}

@media (max-width: 690px) {
    .clock {
        flex: 0 1 30%;
    }

    .clock-text {
        font-size: clamp(14px, 4vw, 36px);
    }

    .energy {
        flex: 1 1 70%;
    }

    .energy-slots {
        inset: 18% 6% 18% 15%;
    }

    .energy .cell {
        width: clamp(22px, 5.6vw, 44px);
    }

    .title {
        height: clamp(40px, 12vw, 101px);
        width: clamp(200px, 48vw, 384px);
        left: 19%;
        top: -3%;
    }

    .atext {
        font-size: clamp(9px, 2.8vw, 24px);
        padding: 0 0 0 26px;
    }

    .qtext {
        font-size: clamp(14px, 3vw, 28px);
    }

    .btn-area.next {
        right: -2%;
        top: 0px;
    }

    :root {
        --clock-ratio: 2/ 1;
        --energy-ratio: 7 / 1;
        --answer-ratio: 2.7 / 1;
    }

    .tick{
        right: 8%;
    }

    .testarea{
        width: 74%;
        margin-left: 11%;
    }
}

@media (max-width: 450px) {
    .result-stage{
        margin: 15% 1%;
        justify-content: flex-start;
    }

    .result-board{
        padding: 10px;
        min-height: 565px;
        gap: 0px;
    }

    .grade-text{
        margin: 0px;
    }
}

/* === 時間到覆蓋層 === */
.timeup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;                /* 預設隱藏 */
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* 顯示狀態（例如時間到時加上 body.show-timeup） */
.show-timeup .timeup-overlay {
  display: flex;
}

/* 內容卡片 */
.timeup-card {
  background: #1f1f2a;
  border: 3px solid #66f7cf;
  border-radius: 18px;
  padding: 40px 60px;
  text-align: left;
  color: #fff;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.4);
  animation: popup-in 0.3s ease-out;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 標題 */
.timeup-title {
  font-size: clamp(14px, 2vw, 32px);
  font-weight: 700;
  margin-bottom: 30px;
  color: #66f7cf;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.itro-btn-area{
  display: flex;
  gap: 20px;
}

/* 彈出動畫 */
@keyframes popup-in {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* 直接沿用現有 .btn-confirm 樣式 */
.timeup-card .btn-confirm {
  margin-top: 10px;
  position: relative;
  transform: unset;
  right: unset;
  bottom: unset;
  font-size: clamp(14px, 2vw, 20px);
}

@media (max-width: 960px){
  .timeup-card{
    margin: 0 10px;
    padding: 20px 20px;
  }

  .timeup-title{
    margin-bottom: 10px;
  }
}