* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /*タブレット連打時の拡大防止 */
}

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

body {
  font-family: 'Rounded Mplus 1c', 'M PLUS Rounded 1c', 'Hiragino Maru Gothic Pro', 'Yu Gothic', sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

button {
  font-family: inherit;
}

.container {
  width: 100%;
  max-width: 1196px;
  height: 540px;
  margin: 0 auto;
  background: #ffffff;
  border: 2px solid #333;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.game-header {
  position: relative;
  flex: 0 0 50px;
  height: 50px;
  padding: 10px 16px;
  background: #ffffff;
  display: flex;
  align-items: center;
}

.info {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  font-weight: bold;
}

.info span:first-child {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.game-main {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #ffffff;
  overflow: hidden;
}

.flash-anzan {
    width: 100%;
    max-width: 1196px;
    height: 100%;
    position: relative;
    overflow: hidden;
    }

  .screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .screen.active { display: flex; }
  #screen-title {
    background: linear-gradient(160deg, #ffe066 0%, #ff9f43 50%, #ff6b9d 100%);
  }
  .title-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
  .bubble {
    position: absolute; border-radius: 50%; opacity: 0.22;
    animation: floatUp 6s ease-in-out infinite;
  }
  @keyframes floatUp {
    0%,100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-18px) scale(1.05); }
  }
  .title-card {
    background: rgba(255,255,255,0.93);
    border-radius: 28px;
    padding: 32px 52px 28px;
    text-align: center;
    box-shadow: 0 6px 32px rgba(255,120,60,0.25);
    z-index: 1;
    max-width: 480px;
    width: 90%;
  }
  .title-icon {
    font-size: 52px; line-height: 1; margin-bottom: 6px;
    animation: bounce 1.4s ease-in-out infinite;
  }
  @keyframes bounce {
    0%,100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
  }
  .title-main {
    font-size: 40px; font-weight: 900; letter-spacing: 4px;
    background: linear-gradient(135deg, #ff6b9d, #ff9f43, #ffe066);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px; line-height: 1.2;
  }
  .title-sub { font-size: 15px; color: #f97316; font-weight: 700; letter-spacing: 2px; margin-bottom: 24px; }
  .level-label { font-size: 14px; font-weight: 700; color: #aaa; margin-bottom: 10px; letter-spacing: 2px; }
  .level-btns { display: flex; gap: 8px; justify-content: center; margin-bottom: 22px; flex-wrap: nowrap; }
  .btn-level {
    box-sizing: border-box; padding: 11px 16px; border-radius: 50px; border: 3px solid transparent;
    font-size: 17px; font-weight: 800; cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, border-width 0.15s;
    letter-spacing: 1px; outline: none;
    background: #e0f2fe; border-color: #38bdf8; color: #0369a1;
    font-family: inherit;
  }
  .btn-level:hover { transform: scale(1.06); }
  #btn-easy.btn-level   { background: #d1fae5; border-color: #6ee7b7; color: #047857; }
  #btn-normal.btn-level { background: #fef3c7; border-color: #fcd34d; color: #b45309; }
  #btn-hard.btn-level   { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
  .btn-level.sel-easy   { background: #bbf7d0; border-color: #059669; border-width: 5px; color: #047857; box-shadow: 0 6px 18px #34d39955; transform: scale(1.04); }
  .btn-level.sel-normal { background: #fde68a; border-color: #d97706; border-width: 5px; color: #92400e; box-shadow: 0 6px 18px #fbbf2455; transform: scale(1.04); }
  .btn-level.sel-hard   { background: #fecaca; border-color: #dc2626; border-width: 5px; color: #991b1b; box-shadow: 0 6px 18px #f8717155; transform: scale(1.04); }
  .btn-start {
    background: linear-gradient(135deg, #ff6b9d, #ff9f43);
    color: #fff; border: none; border-radius: 50px;
    padding: 15px 56px; font-size: 21px; font-weight: 900;
    cursor: pointer; letter-spacing: 3px;
    box-shadow: 0 6px 20px rgba(255,107,157,0.4);
    transition: transform 0.15s, box-shadow 0.15s, border-width 0.15s; outline: none;
    font-family: inherit;
  }
  .btn-start:hover  { transform: scale(1.06); box-shadow: 0 8px 28px rgba(255,107,157,0.5); }
  .btn-start:active { transform: scale(0.98); }
  .btn-start:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: none; }
  #screen-ready {
    background: linear-gradient(160deg, #667eea 0%, #764ba2 100%);
  }
  .ready-card {
    text-align: center; z-index: 1;
  }
  .ready-text {
    font-size: 36px; font-weight: 900; color: #fff;
    letter-spacing: 4px; margin-bottom: 36px;
    text-shadow: 0 3px 16px rgba(0,0,0,0.25);
    line-height: 1.35;
  }
  .ready-countdown {
    font-size: 110px; font-weight: 900; color: #fff;
    line-height: 1; min-height: 120px;
    text-shadow: 0 0 40px rgba(255,210,0,0.7), 0 4px 16px rgba(0,0,0,0.3);
    animation: cdPop 0.35s cubic-bezier(0.34,1.56,0.64,1);
  }
  @keyframes cdPop {
    from { transform: scale(0.3); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
  }
  .ready-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
  .r-bubble {
    position: absolute; border-radius: 50%; opacity: 0.18;
    animation: floatUp 5s ease-in-out infinite;
  }
  #screen-play {
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
    flex-direction: column; gap: 0;
  }
  .play-header {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; align-items: center; justify-content: flex-end;
    padding: 18px 32px; z-index: 10;
  }
  .answer-progress {
    position: absolute; top: 20px; left: 32px;
    display: flex; align-items: center; gap: 8px; z-index: 10;
  }
  .answer-progress-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: rgba(255,255,255,0.42);
    border: 2px solid rgba(125,211,252,0.45);
    box-shadow: 0 0 0 1px rgba(255,255,255,0.12) inset;
  }
  .answer-progress-dot.done {
    background: #22c55e; border-color: #16a34a;
    box-shadow: 0 0 8px rgba(34,197,94,0.45);
  }
  .answer-progress-dot.current {
    width: 18px; height: 18px;
    background: #facc15; border-color: #eab308;
    box-shadow: 0 0 10px rgba(250,204,21,0.5);
  }
  .btn-quit {
    background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50px; padding: 10px 24px;
    color: #fff; font-size: 15px; font-weight: 700;
    cursor: pointer; letter-spacing: 2px;
    transition: background 0.15s; outline: none; font-family: inherit;
  }
  .btn-quit:hover { background: rgba(255,255,255,0.28); }
  .flash-area {
    display: flex; align-items: center; justify-content: center;
    flex: 1; width: 100%;
    padding-top: 80px; padding-bottom: 20px; position: relative;
  }
  .flash-number {
    font-size: 220px; font-weight: 900; line-height: 1; color: #fff;
    text-shadow: 0 0 60px rgba(255,210,0,0.6), 0 4px 20px rgba(0,0,0,0.4);
    letter-spacing: 0; transition: opacity 0.06s;
  }
  .flash-number.hidden { opacity: 0; }
  .flash-tasu {
    font-size: 52px; font-weight: 900; letter-spacing: 6px;
    color: #60a5fa;
    text-shadow: 0 0 30px rgba(96,165,250,0.7);
    transition: opacity 0.06s;
    display: none;
  }
  .flash-tasu.show { display: block; }
  .flash-tasu.hidden { opacity: 0; }
  .flash-sign { display: none; }
  .progress-bar-wrap { display: none; }
  #screen-answer {
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
    padding: 0 32px;
  }
  .answer-wrap {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; position: relative;
  }
  .answer-left {
    position: absolute; left: 80px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; align-items: center;
    gap: 14px;
  }
  .hint-panel {
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(96,165,250,0.4);
    border-radius: 20px; padding: 18px 28px;
    text-align: center; min-width: 220px;
    display: none;
  }
  .hint-panel.visible { display: block; animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1); }
  .hint-label { font-size: 13px; color: #60a5fa; font-weight: 700; letter-spacing: 2px; margin-bottom: 10px; }
  .hint-formula {
    font-size: 28px; font-weight: 900; color: #fff;
    letter-spacing: 3px; line-height: 1.5;
    white-space: nowrap;
  }
  .hint-formula .hf-num  { color: #ffd700; }
  .hint-formula .hf-plus { color: #60a5fa; font-size: 22px; }
  .btn-replay {
    background: rgba(255,210,0,0.15); border: 2px solid rgba(255,210,0,0.45);
    border-radius: 50px; color: #fde68a; font-size: 16px; font-weight: 800;
    padding: 12px 28px; cursor: pointer; letter-spacing: 2px;
    transition: background 0.15s, transform 0.12s; outline: none; font-family: inherit;
  }
  .btn-replay:hover { background: rgba(255,210,0,0.28); transform: scale(1.05); }
  .btn-replay:active { transform: scale(0.96); }
  .btn-hint {
    background: rgba(96,165,250,0.18); border: 2px solid rgba(96,165,250,0.5);
    border-radius: 50px; color: #93c5fd; font-size: 16px; font-weight: 800;
    padding: 12px 28px; cursor: pointer; letter-spacing: 2px;
    transition: background 0.15s, transform 0.12s; outline: none; font-family: inherit;
  }
  .btn-hint:hover { background: rgba(96,165,250,0.32); transform: scale(1.05); }
  .btn-hint.active { background: rgba(96,165,250,0.35); border-color: #60a5fa; color: #fff; }
  .btn-quit-ans {
    position: absolute; top: 18px; right: 32px;
    background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50px; color: #fff; font-size: 15px;
    font-weight: 700; padding: 10px 24px; cursor: pointer;
    letter-spacing: 2px; outline: none; font-family: inherit;
    transition: background 0.15s; z-index: 10;
  }
  .btn-quit-ans:hover { background: rgba(255,255,255,0.28); }
  .answer-card {
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 24px; padding: 24px 28px 28px;
    text-align: center; width: 320px; flex-shrink: 0;
  }
  .answer-title { font-size: 17px; color: rgba(255,255,255,0.65); letter-spacing: 3px; margin-bottom: 10px; font-weight: 700; }
  .answer-display {
    font-size: 64px; font-weight: 900; color: #fff;
    letter-spacing: 4px; min-height: 72px; line-height: 1;
    margin-bottom: 0; text-shadow: 0 0 30px rgba(255,210,0,0.5);
  }
  .answer-display .cursor {
    display: inline-block; width: 4px; height: 56px;
    background: #ffd700; vertical-align: middle; margin-left: 3px;
    animation: blink 0.8s step-end infinite;
  }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
  .numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 24px 0; }
  .btn-num {
    background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.18);
    border-radius: 12px; color: #fff; font-size: 22px; font-weight: 800;
    padding: 11px 0; cursor: pointer;
    transition: background 0.12s, transform 0.1s; outline: none; font-family: inherit;
  }
  .btn-num:hover  { background: rgba(255,255,255,0.24); transform: scale(1.04); }
  .btn-num:active { transform: scale(0.95); }
  .btn-zero { grid-column: 1 / 3; }
  .btn-del  { background: rgba(255,100,100,0.2); border-color: rgba(255,100,100,0.35); font-size: 14px; letter-spacing: 1px; }
  .btn-answer-ok {
    width: 180px;
    background: linear-gradient(135deg, #34d399, #059669);
    border: none; border-radius: 50px; color: #fff;
    font-size: 16px; font-weight: 900; padding: 12px 28px;
    cursor: pointer; letter-spacing: 2px;
    box-shadow: 0 4px 18px rgba(52,211,153,0.4);
    transition: transform 0.12s, box-shadow 0.12s; outline: none; font-family: inherit;
  }
  .btn-answer-ok:hover  { transform: scale(1.03); box-shadow: 0 6px 26px rgba(52,211,153,0.55); }
  .btn-answer-ok:active { transform: scale(0.97); }
  #screen-feedback {
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  }
  .feedback-card {
    padding: 36px 48px 32px;
    text-align: center; width: 480px; max-width: 92%;
    animation: popIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
  }
  .feedback-card.ok   { background: rgba(52,211,153,0.15); border: 3px solid #34d399; }
  .feedback-card.ng   { background: rgba(248,113,113,0.12); border: 3px solid #f87171; }
  @keyframes popIn {
    from { transform: scale(0.6); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
  }
  .fb-emoji { font-size: 72px; line-height: 1; margin-bottom: 10px; }
  .fb-formula {
    font-size: 22px; font-weight: 700; color: rgba(255,255,255,0.8);
    letter-spacing: 2px; margin-bottom: 6px;
    background: rgba(255,255,255,0.07); border-radius: 14px; padding: 12px 20px;
  }
  .fb-answer-lead { color: rgba(255,255,255,0.65); font-size: 18px; font-weight: 900; margin-bottom: 8px; letter-spacing: 2px; }
  .fb-formula .correct-ans { color: #ffd700; font-size: 28px; font-weight: 900; }
  .fb-formula .user-ans    { color: #f87171; font-size: 24px; font-weight: 900; }
  .fb-user-answer { margin-top: 10px; color: rgba(255,255,255,0.7); font-size: 18px; font-weight: 800; }
  .btn-feedback-next {
    background: linear-gradient(135deg, #34d399, #059669);
    border: none; border-radius: 50px; color: #fff;
    font-size: 20px; font-weight: 900; padding: 13px 44px;
    cursor: pointer; letter-spacing: 3px;
    box-shadow: 0 5px 20px rgba(52,211,153,0.42);
    transition: transform 0.12s, box-shadow 0.12s;
    outline: none; font-family: inherit;
  }
  .btn-feedback-next:hover { transform: scale(1.05); box-shadow: 0 7px 26px rgba(52,211,153,0.55); }
  .btn-feedback-next:active { transform: scale(0.97); }
  #screen-result {
    background: linear-gradient(160deg, #ffe066 0%, #ff9f43 50%, #ff6b9d 100%);
  }
  .stars-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
  .star {
    position: absolute; font-size: 22px;
    animation: starFloat 4s ease-in-out infinite; opacity: 0.7;
  }
  @keyframes starFloat {
    0%,100% { transform: translateY(0) rotate(0deg); }
    50%      { transform: translateY(-14px) rotate(20deg); }
  }
  .result-card {
    background: rgba(255,255,255,0.93); border-radius: 28px;
    padding: 28px 44px 28px; text-align: center;
    box-shadow: 0 8px 40px rgba(255,100,60,0.22);
    width: 460px; max-width: 92%; z-index: 1;
    animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
  }
  .result-title { font-size: 28px; font-weight: 900; margin-bottom: 18px; letter-spacing: 2px; }
  .result-title.perfect { color: #f97316; }
  .result-title.great   { color: #059669; }
  .result-title.good    { color: #d97706; }
  .result-title.tryagain { color: #dc2626; }
  .result-stats {
    display: flex; justify-content: center; gap: 20px;
    margin-bottom: 20px; flex-wrap: wrap;
  }
  .result-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .stat-val { font-size: 42px; font-weight: 900; line-height: 1; }
  .stat-val.green  { color: #059669; }
  .stat-val.red    { color: #dc2626; }
  .stat-val.orange { color: #f97316; }
  .stat-label { font-size: 12px; color: #aaa; font-weight: 700; letter-spacing: 1px; }
  .result-btns { display: flex; gap: 12px; justify-content: center; }
  .btn-retry {
    background: linear-gradient(135deg, #ff6b9d, #ff9f43);
    color: #fff; border: none; border-radius: 50px;
    padding: 13px 32px; font-size: 17px; font-weight: 900;
    cursor: pointer; letter-spacing: 2px;
    box-shadow: 0 4px 18px rgba(255,107,157,0.4);
    transition: transform 0.12s; outline: none; font-family: inherit;
  }
  .btn-retry:hover { transform: scale(1.05); }
  .btn-home {
    background: #f0f0f0; color: #888; border: 2px solid #ddd;
    border-radius: 50px; padding: 13px 28px; font-size: 17px;
    font-weight: 800; cursor: pointer; letter-spacing: 2px;
    transition: transform 0.12s, background 0.12s; outline: none; font-family: inherit;
  }
  .btn-home:hover { background: #e4e4e4; transform: scale(1.04); }

  @media (max-width: 420px) {
    .title-card { padding-left: 18px; padding-right: 18px; }
    .level-btns { gap: 6px; }
    .btn-level { padding: 10px 10px; font-size: 15px; letter-spacing: 0; }
  }

  @media (max-width: 360px) {
    .title-card { padding-left: 16px; padding-right: 16px; }
    .level-btns { gap: 5px; }
    .btn-level { padding: 9px 8px; font-size: 14px; }
  }
  .confetti-piece {
    position: absolute; width: 10px; height: 14px; border-radius: 2px;
    animation: confettiFall linear forwards; pointer-events: none;
  }
  @keyframes confettiFall {
    0%   { top: -20px; opacity: 1; transform: rotate(0deg) translateX(0); }
    100% { top: 620px; opacity: 0; transform: rotate(720deg) translateX(80px); }
  }
