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

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    min-height: 100vh;
    /* Theme */
    --bg: #101419;
    --panel: #2d343c;
    --panel-raised: #333a43;
    --text: #e6eaf0;
    --muted: #aab3bd;
    --accent: #2196F3;
    --accent-2: #4CAF50;
    --warning: #FF9800;
    --ring: rgba(33,150,243,.55);
    --shadow-1: 0 4px 16px rgba(0,0,0,.45);
    --shadow-2: 0 12px 32px rgba(0,0,0,.5);

    /* Switch page background to dark to match the app */
    background: radial-gradient(1200px 600px at 20% 0%, #121821 0, var(--bg) 60%) fixed;
    color: var(--text); /* default text color for any outer text */
    /* Avoid content hidden behind mobile browser UI / notches */
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    /* Legacy iOS fallback */
    padding-top: constant(safe-area-inset-top);
    padding-right: constant(safe-area-inset-right);
    padding-bottom: constant(safe-area-inset-bottom);
    padding-left: constant(safe-area-inset-left);
    overflow-y: auto;
    overflow-x: hidden;
}

/* GitHub Corner (right-top cut-corner) */
.github-corner {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000; /* below restart button */
  display: block;
  width: 80px;
  height: 80px;
  /* Restrict clickable area to the visible triangle */
  -webkit-clip-path: polygon(100% 0, 0 0, 100% 100%);
          clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.github-corner svg {
  /* Match the dark page background for a seamless corner */
  fill: #101419; /* corner background */
  color: #fff;   /* octocat color */
  width: 80px;
  height: 80px;
}
.github-corner .octo-arm { transform-origin: 130px 106px; }
.github-corner:hover .octo-arm { animation: octocat-wave 560ms ease-in-out; }
@keyframes octocat-wave {
  0%, 100% { transform: rotate(0); }
  20%, 60% { transform: rotate(-25deg); }
  40%, 80% { transform: rotate(10deg); }
}
/* On small screens, auto-wave without hover for accessibility */
@media (max-width: 500px) {
  .github-corner:hover .octo-arm { animation: none; }
  .github-corner .octo-arm { animation: octocat-wave 560ms ease-in-out; }
}

.mixer-container {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-raised) 100%);
    color: var(--text);
    padding: 20px;
    border-radius: 10px;
    /* Slight border to keep a subtle boundary on dark outer bg */
    border: 1px solid rgba(255,255,255,0.06);
    box-shadow: var(--shadow-2);
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 800px;
    margin: 16px auto;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  /* Share a single title size so logo matches text */
  --title-size: clamp(28px, 3.8vw, 40px);
}

.app-logo {
  width: var(--title-size);
  height: var(--title-size);
  display: block;
}

.app-title {
  margin: 0 0 5px 0;
  font-size: var(--title-size);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: .5px;
  background: linear-gradient(90deg, #e6f3ff 0%, #bfe2ff 40%, #9ecfff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 12px rgba(0,0,0,.35);
  position: relative;
  display: inline-block;
}
.app-title::after {
  content: "";
  position: absolute;
  left: 2px;
  bottom: -6px;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, #80d8ff 100%);
  box-shadow: 0 2px 8px rgba(33,150,243,.45);
}
@media (max-width: 520px) {
  .app-title::after { width: 100%; height: 3px; bottom: -5px; }
}

#restartBtn {
    background: linear-gradient(180deg, #ffab2e, var(--warning)); /* 強調再玩一次 */
    border: none;
    color: #1a1a1a;
    padding: 8px 14px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    position: relative;
    z-index: 2000; /* ensure above github-corner */
}

#restartBtn:disabled {
    background-color: #BDBDBD;
    color: #F5F5F5;
    cursor: default;
}

#restartBtn:not(:disabled):hover { filter: brightness(1.05); }
#restartBtn:not(:disabled):active { transform: translateY(1px); }
#restartBtn:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.transport-controls {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    min-width: 0; /* allow children to shrink on small screens */
}

#playPauseBtn {
    background: linear-gradient(180deg, #66bb6a, var(--accent-2));
    border: none;
    color: white;
    padding: 10px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin-right: 10px;
    cursor: pointer;
    border-radius: 5px;
}

#playPauseBtn:disabled {
    background-color: #607D8B; /* 載入中：藍灰，表示忙碌且不可互動 */
    color: #ECEFF1;
    cursor: default;
}

#playPauseBtn:not(:disabled):hover { filter: brightness(1.06); }
#playPauseBtn:not(:disabled):active { transform: translateY(1px); }
#playPauseBtn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

#timeSlider {
    flex-grow: 1;
    min-width: 0; /* prevent overflow in flex container */
    -webkit-appearance: none;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(180deg, #cfd8dc, #b0bec5);
    outline: none;
}
#timeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
#timeSlider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
#timeSlider:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.faders-container {
    display: flex;
    justify-content: space-between;
    flex-wrap: nowrap; /* keep all 7 in one row */
    gap: 8px;
}

.fader {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 10px 20px;
}

/* Make each slider share width and be shrinkable */
.faders-container > volume-slider {
    flex: 1 1 0;
    min-width: 0; /* allow shrinking below content width */
}

.fader input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 20px;
    height: 150px;
    margin: 0 10px;
}

.fader label {
    margin-top: 10px;
    text-align: center;
}

.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

#submitBtn {
    background: linear-gradient(180deg, #64b5f6, var(--accent));
    border: none;
    color: white;
    padding: 10px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer; /* only when enabled */
    border-radius: 5px;
}

#submitBtn:disabled {
    background-color: #9E9E9E; /* 完成：灰色，表示未啟用 */
    color: #F5F5F5;
    cursor: default; /* do not show pointer when disabled */
}

#submitBtn:not(:disabled):hover { filter: brightness(1.06); }
#submitBtn:not(:disabled):active { transform: translateY(1px); }
#submitBtn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.toggle-container {
    display: flex;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 84px;
    height: 36px;
    margin: 0 10px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #cfd8dc, #b0bec5);
    transition: background-color .25s ease, transform .1s ease;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 28px;
    width: 28px;
    left: 4px;
    bottom: 4px;
    background: radial-gradient(circle at 30% 30%, #fff, #e3e7eb);
    box-shadow: 0 2px 6px rgba(0,0,0,.3);
    transition: left .25s ease;
    border-radius: 50%;
}

input:checked + .slider {
    background: linear-gradient(180deg, #64b5f6, var(--accent));
}

input:checked + .slider:before {
    /* Move knob to the precise right stop: width - knob - right-gap */
    left: calc(100% - 28px - 4px);
}

.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px var(--ring) inset; }

#scoreDisplay {
    font-size: 18px;
    font-weight: bold;
}

@media (max-width: 600px) {
    .mixer-container {
        padding: 10px;
        width: 95%;
    }

    .faders-container {
        justify-content: space-between; /* keep in one row */
    }

    .fader {
        margin: 0 2px 10px;
    }

    .game-controls {
        flex-direction: row;
        flex-wrap: wrap;             /* allow items to wrap to new row */
        align-items: center;
        justify-content: space-between; /* submit left, score right on second row */
    }

    /* Mobile order: toggle on first full row; then submit+score same row */
    #modeToggle { order: 1; flex: 1 1 100%; }
    #submitBtn { order: 2; }
    #scoreContainer { order: 2; }

    #modeToggle,
    #submitBtn,
    #scoreContainer {
        margin-bottom: 10px;
    }

    /* Ensure toggle labels are vertically centered around the switch */
    #modeToggle {
        display: flex;
        align-items: center;
        justify-content: center; /* center the toggle horizontally */
    }
    #modeToggle span {
        display: inline-flex;
        align-items: center;
        white-space: nowrap; /* avoid wrapping labels in mobile */
        line-height: 1.2;
    }
}

.toggle-container {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.toggle-container span {
    margin: 0 10px;
}

/* Toggle label states */
.toggle-label {
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 600;
    user-select: none;
    transition: background-color .2s ease, color .2s ease, opacity .2s ease;
}
.toggle-label.active {
    background-color: var(--accent);
    color: #fff;
    cursor: default;
    opacity: 1;
}
.toggle-label.inactive {
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    text-decoration: underline dotted;
}
.toggle-label[aria-disabled="true"] {
    pointer-events: none;
}
