:root {
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100dvw;
  height: 100dvh;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Helvetica Neue", Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  color: #ffffff;
  background-color: #141820;
}

#game-area {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  padding-top: var(--safe-area-inset-top);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
  padding-left: var(--safe-area-inset-left);
  overflow: hidden;
}

#assets {
  display: none;
}

/* 言語切り替え */
html[lang="ja"] .lang-en,
html:not([lang="ja"]) .lang-ja {
  display: none;
}

/****************************************
** Canvas Container
*/

#canvas-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/****************************************
** Screen & Overlay Visibility
*/

body:not(.title-screen-active) .title-screen,
body:not(.game-screen-active) .game-header,
body:not(.info-active) .info-overlay,
body:not(.paused-active) .paused-overlay,
body:not(.finished-active) .finished-overlay,
body:not(.shake-available) .shake-button {
  display: none;
}

body:not(.game-screen-active) .shake-button,
body.paused-active .shake-button,
body.finished-active .shake-button {
  display: none;
}

body.finished-active .game-header .pause-button {
  display: none;
}

/****************************************
** Game Header / HUD
*/

.game-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 52px;
  padding: 0 10px;
  background-color: rgba(12, 16, 22, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.time-indicator {
  position: absolute;
  inset: 0;
  background-color: rgba(210, 24, 58, 0.82);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease-out;
}

body.time-warning-pulse .time-indicator {
  opacity: 1;
  transition: none;
}

.hud-group {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #f3f6fa;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  line-height: 1.1;
  margin-bottom: 2px;
}

.hud-combo {
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

body.combo-active .hud-combo {
  opacity: 1;
  transform: translateY(0);
}

.hud-score {
  flex: 1;
  min-width: 0;
}

.digits-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.digits-3 .digit-img {
  width: 14px;
  height: 19px;
  object-fit: contain;
}

.digits-8 .digit-img {
  width: 17px;
  height: 23px;
  object-fit: contain;
}

@media (max-width: 520px) {
  .game-header {
    gap: 4px;
    padding: 0 6px;
  }
  .digits-3 .digit-img {
    width: 11px;
    height: 15px;
  }
  .digits-8 .digit-img {
    width: 13px;
    height: 18px;
  }
}

.hud-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sound-button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.sound-button:focus-visible,
.pause-button:focus-visible,
.shape-action-button:focus-visible,
.shake-button:focus-visible,
.modal-ok-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.sound-button img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

body.sound-enabled .sound-button.sound-disabled-button,
body.sound-disabled .sound-button.sound-enabled-button {
  display: none;
}

.pause-button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  margin: 2px;
  border: solid 1px #ffffff;
  border-radius: 50px;
  cursor: pointer;
}

.pause-button img {
  width: 30px;
  height: 30px;
  filter: brightness(0) invert(1);
}

body:not(.paused-active) .pause-icon-active,
body.paused-active .pause-icon-idle {
  display: none;
}

/****************************************
** Message Banner
*/

.message-banner {
  position: absolute;
  top: 76px;
  left: 0;
  right: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  height: 44px;
  background-color: rgba(255, 255, 255, 0.72);
  color: #044731;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease;
}

body.message-visible .message-banner {
  display: flex;
}

body.message-fading .message-banner {
  opacity: 0;
  transition: opacity 1.6s ease;
}

.msg-text {
  display: none;
}

body.msg-time-extended .msg-time-extended,
body.msg-shaked .msg-shaked,
body.msg-paused .msg-paused,
body.msg-finished .msg-finished,
body.msg-game-over .msg-game-over {
  display: inline;
}

/****************************************
** Shake Button
*/

@keyframes shakeHue {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

@keyframes popIn {
  0% { transform: scale(0.05); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.shake-button {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 22;
  width: 68px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff8a3d, #d93870);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  animation: popIn 0.45s cubic-bezier(0.16, 1, 0.3, 1), shakeHue 6s linear infinite;
}

.shake-button:active {
  transform: scale(0.92);
}

/****************************************
** Title Screen
*/

.title-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px 24px;
}

.title-sound-wrap {
  position: absolute;
  top: 16px;
  right: 16px;
}

.title-sound-btn {
  background: rgba(20, 24, 34, 0.65);
  width: 44px;
  height: 44px;
}

.title-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 460px;
  width: 100%;
}

.title-logo-wrap {
  margin-bottom: 14px;
}

.title-logo-img {
  max-width: 300px;
  width: 80vw;
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.16));
}

.title-desc {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.55;
  color: #181a20;
  margin-bottom: 28px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
}

.title-buttons,
.overlay-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
}

/****************************************
** Shape Action Buttons (Original ShapeView Style)
*/

.shape-action-button {
  position: relative;
  width: 124px;
  height: 124px;
  border: none;
  background: transparent;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.shape-action-button::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  animation: shakeHue 7s linear infinite;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5);
}

.shape-action-button:hover {
  transform: scale(1.05);
}

.shape-action-button:active {
  transform: scale(0.95);
}

.shape-pentagon::before {
  background: linear-gradient(135deg, #ff5983, #ffb347);
  clip-path: polygon(50% 2%, 98% 37%, 80% 95%, 20% 95%, 2% 37%);
  border-radius: 20px;
}

.shape-octagon::before {
  background: linear-gradient(135deg, #36b5ff, #65e095);
  clip-path: polygon(50% 2%, 75% 12%, 94% 30%, 98% 54%, 88% 80%, 66% 96%, 34% 96%, 12% 80%, 2% 54%, 6% 30%, 25% 12%);
}

.shape-circle::before {
  background: linear-gradient(135deg, #7c6bff, #3dd5f3);
  border-radius: 50%;
}

/****************************************
** Info, Paused, Finished Overlays
*/

.info-overlay,
.paused-overlay,
.finished-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px 24px;
}

.info-overlay {
  z-index: 45;
  background: rgba(10, 14, 22, 0.68);
  backdrop-filter: blur(4px);
}

.info-card {
  width: 100%;
  max-width: 440px;
  max-height: 85dvh;
  overflow-y: auto;
  background: #f5f7fa;
  color: #1a202c;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  text-align: left;
}

.info-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 14px;
  text-align: center;
  color: #8c1c4e;
}

.info-body p {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 12px;
  color: #2d3748;
}

.modal-ok-button {
  display: block;
  margin: 16px auto 0;
  min-width: 120px;
  min-height: 44px;
  padding: 10px 28px;
  border: none;
  border-radius: 999px;
  background: #c72e73;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.modal-ok-button:hover {
  background: #a5225d;
}

/****************************************
** Result Card
*/

.finished-overlay {
  gap: 20px;
}

.result-card {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 340px;
  background: #eaeef5;
  color: #181c24;
  border: 6px solid #1f2430;
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  text-align: center;
}

body.result-active .result-card {
  display: flex;
}

body.result-active .finished-overlay .overlay-buttons {
  display: none;
}

.result-rank {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.rank-text {
  display: none;
}

body.rank-novice .rank-novice,
body.rank-bronze .rank-bronze,
body.rank-silver .rank-silver,
body.rank-gold .rank-gold,
body.rank-platinum .rank-platinum {
  display: inline;
}

.result-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 26px;
  color: #ffbe0b;
  -webkit-text-stroke: 1.5px #1a1a1a;
}

.result-star {
  display: none;
}

body.rank-novice .star-1,
body.rank-bronze .star-1,
body.rank-bronze .star-2,
body.rank-silver .star-1,
body.rank-silver .star-2,
body.rank-silver .star-3,
body.rank-gold .star-1,
body.rank-gold .star-2,
body.rank-gold .star-3,
body.rank-gold .star-4,
body.rank-platinum .result-star {
  display: inline-block;
}

.result-digits {
  margin-bottom: 12px;
}

.result-digits .digit-img {
  width: 24px;
  height: 32px;
}

.result-meta {
  font-size: 14px;
  font-weight: 800;
  color: #252b36;
}

.modal-ok-button-wrap {
  min-height: 60px;
}

body.clear-process-paused #resultOkButton {
  display: none;
}
