  :root {
    --bg: #12141c;
    --panel: #1d212c;
    --accent: #ffb454;
    --accent2: #57c7ff;
    --success: #06d6a0;
    --fail: #ff5f5f;
    --text: #f1f3f9;
    --muted: #7d859b;
    --border-glow: #57c7ff;
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    background: #000;
    color: var(--text);
    font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
    overscroll-behavior: none;
    touch-action: manipulation;
    overflow: hidden;
  }
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }
  #viewport {
    width: 100vw;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
  }
  #adArea {
    flex: 0 0 auto;
    width: 100%;
    min-height: 50px;
    max-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000;
  }
  #bottomSafeArea {
    flex: 0 0 auto;
    width: 100%;
    height: max(20px, env(safe-area-inset-bottom, 0px));
    background: #000;
  }
  #stage {
    width: 375px;
    height: 667px;
    flex-shrink: 0;
    position: relative;
    background: var(--bg);
    overflow: hidden;
    transform-origin: center center;
    box-shadow: 0 0 30px rgba(0,0,0,0.6);
  }
  #app {
    width: 100%;
    height: 100%;
    display: flex; flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    position: relative;
  }
  h1 { margin: 6px 0 2px; font-size: 19px; letter-spacing: 2px; }
  .title-logo {
    display: block;
    width: 82%;
    max-width: 360px;
    height: auto;
    margin: 6px 0 2px;
  }
  h2 { margin: 6px 0; color: var(--accent); }
  button {
    -webkit-appearance: none; appearance: none;
    width: 62%; max-width: 260px; padding: 13px; margin: 5px 0;
    font-size: 15px; border-radius: 12px; border: none;
    background: var(--panel); color: var(--text);
    cursor: pointer; transition: transform .08s ease, background .15s ease;
  }
  button:hover:not(:disabled) { background: #2a3142; }
  button:active:not(:disabled) { transform: scale(0.96); }
  button:disabled { opacity: 0.35; cursor: not-allowed; }
  button.primary { background: var(--accent); color: #14171f; font-weight: bold; }
  button.primary:hover:not(:disabled) { background: #ffc472; }
  button.diff-btn { width: 78%; max-width: 320px; white-space: nowrap; font-size: 15px; padding: 12px 8px; }
  button.link-btn {
    width: auto; max-width: none; background: none; border: none;
    color: var(--accent2); text-decoration: underline; font-size: 13px;
    padding: 6px; margin-top: 4px;
  }
  .mrs-games-link {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 10px;
    color: var(--muted);
    font-size: 12px;
    text-decoration: underline;
    transition: color 0.2s;
  }
  .mrs-games-link:active,
  .mrs-games-link:hover {
    color: var(--text);
  }

  .screen { display: none; flex-direction: column; align-items: center; width: 100%; height: 100%; }

  #topBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 4px;
    flex-shrink: 0;
  }

  #leftCol {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--muted);
  }
  #scoreVal { color: var(--text); font-weight: bold; font-size: 16px; }

  button.pause-btn {
    width: 38px; height: 38px; padding: 0; margin: 0;
    border-radius: 50%; font-size: 18px;
    background: var(--panel);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }

  #eqRow {
    display: flex;
    align-items: stretch;
    width: 100%;
    gap: 6px;
    margin: 2px 0 4px;
    flex-shrink: 0;
  }

  #equationBar {
    flex: 1 1 auto;
    font-size: 19px; font-weight: bold; letter-spacing: 1px;
    background: var(--panel); border-radius: 10px;
    padding: 6px 6px; margin: 0;
    display: flex; align-items: center; justify-content: center; gap: 3px;
    flex-wrap: nowrap;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
    min-width: 0;
  }
  .slot {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 7px;
    background: #12151d; border: 2px dashed var(--muted);
    font-size: 17px; flex-shrink: 0;
  }
  .slot.filled { border-style: solid; border-color: var(--accent); color: var(--accent); }
  .opsign { color: var(--accent2); font-size: 18px; flex-shrink: 0; }
  .paren { color: var(--muted); font-size: 20px; font-weight: normal; flex-shrink: 0; }
  .eqsign { margin-left: 1px; font-size: 18px; flex-shrink: 0; }
  .targetVal { color: var(--success); font-size: 20px; margin-left: 1px; flex-shrink: 0; }

  button.pass-btn {
    width: 58px;
    height: auto;
    margin: 0;
    padding: 0 8px;
    font-size: 13px;
    font-weight: bold;
    border-radius: 10px;
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  #subBar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 4px;
    flex-shrink: 0;
  }

  #message { min-height: 14px; font-size: 12px; color: var(--accent2); margin: 0; text-align: left; flex-shrink: 1; }

  #nextSection {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 1px;
    flex-shrink: 0;
  }
  .next-box {
    width: 18px; height: 18px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: bold;
    background: #2a3142; color: var(--text);
  }

  .board-area {
    flex: 1 1 auto;
    width: 100%;
    display: flex; align-items: center; justify-content: center;
    min-height: 0;
  }
  .board-box {
    position: relative;
    background: var(--panel);
    border-radius: 10px;
    overflow: hidden;
    border: 3px solid var(--border-glow);
    box-shadow: 0 0 0 1px rgba(87,199,255,0.35), 0 0 18px rgba(87,199,255,0.25), 0 6px 16px rgba(0,0,0,0.55);
  }

  .review-title { width: 100%; max-width: 340px; font-size: 13px; color: var(--accent2); margin: 10px 0 4px; font-weight: bold; }
  .review-list { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 4px; }
  .review-item { background: var(--panel); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
  .review-empty { color: var(--muted); font-size: 12px; padding: 4px 2px; }

  .block {
    position: absolute;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
    border-radius: 7px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
    user-select: none;
    transition: top .32s cubic-bezier(.3,.7,.4,1), box-shadow .15s ease, transform .15s ease;
  }
  .block.landed { cursor: pointer; }
  .block.selected {
    box-shadow: inset 0 0 0 3px #fff, 0 0 10px rgba(255,255,255,.45) !important;
    transform: scale(1.06);
  }
  .block.flash-success { box-shadow: 0 0 0 4px var(--success), 0 0 18px var(--success) !important; }
  .block.flash-fail { box-shadow: 0 0 0 4px var(--fail), 0 0 18px var(--fail) !important; }

  /* 「？」ブロックの小振動 */
  .block.shake-block {
    animation: blockShake 0.25s ease-in-out;
  }
  @keyframes blockShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
  }

  /* 0.5秒の「パーッと強烈に白く光って変身する」エフェクト */
  .block.flash-transform {
    animation: flashTransform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    z-index: 10;
  }
  @keyframes flashTransform {
    0% {
      filter: brightness(1);
      box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
      transform: scale(1);
    }
    50% {
      background: #ffffff !important;
      color: #ffffff !important;
      filter: brightness(3);
      box-shadow: 0 0 25px 12px rgba(255, 255, 255, 0.9);
      transform: scale(1.25);
    }
    100% {
      filter: brightness(1);
      box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
      transform: scale(1);
    }
  }

  #feedbackPop {
    position: fixed; top: 42%; left: 50%;
    transform: translate(-50%, -50%) scale(0.4);
    font-size: 30px; font-weight: 900;
    padding: 12px 26px; border-radius: 16px;
    opacity: 0; pointer-events: none; z-index: 60;
    text-shadow: 0 2px 4px rgba(0,0,0,0.25);
    white-space: nowrap; width: max-content; max-width: 90vw;
  }
  #feedbackPop.show.success { background: rgba(6,214,160,0.96); color: #04241a; animation: popIn .65s ease forwards; }
  #feedbackPop.show.fail { background: rgba(255,95,95,0.96); color: #380000; animation: popIn .65s ease forwards; }
  @keyframes popIn {
    0% { opacity: 0; transform: translate(-50%,-50%) scale(0.4) rotate(-4deg); }
    18% { opacity: 1; transform: translate(-50%,-50%) scale(1.2) rotate(2deg); }
    35% { transform: translate(-50%,-50%) scale(1) rotate(0deg); }
    78% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%,-50%) scale(0.85); }
  }

  button.btn-flash {
    animation: btnFlash 0.2s ease-in-out infinite;
  }
  @keyframes btnFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
  }

  .confirm-modal {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
  }
  .confirm-panel {
    background: var(--panel);
    border-radius: 14px;
    padding: 22px 20px;
    width: 78%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  }
  .confirm-text {
    font-size: 15px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 16px;
    white-space: pre-line;
  }
  .confirm-btn-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
  }