: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);

  --bg-top: #FFF7E8;
  --bg-bottom: #E8F6F2;
  --surface: #FFFFFF;
  --surface-soft: #F8FAFC;
  --ink-primary: #1E293B;
  --ink-secondary: #475569;
  --accent-primary: #FF6B6B;
  --accent-primary-dark: #E05252;
  --accent-secondary: #3B82F6;
  --accent-mint: #10B981;
  --accent-amber: #FF9F1C;
  --border-soft: #E2E8F0;
}

* {
  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: "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--ink-primary);
}

#game-area,
#ad-area {
  width: 100%;
  overflow: hidden;
}

#game-area {
  position: relative;
  flex: 1;
  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);
}

#ad-area {
  display: none;
  flex-shrink: 0;
  height: 60px;
  margin-top: 20px;
}

@media (min-width: 800px) {
  #ad-area {
    height: 90px;
  }
}

#assets {
  display: none;
}

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

/****************************************
** Ad Container
*/

body.has-ad-area {
  padding-bottom: var(--safe-area-inset-bottom);
}

body.has-ad-area #game-area {
  padding-bottom: 0;
}

body.has-ad-area #ad-area {
  display: block;
}

#ad-area .adsbygoogle {
  display: block;
  width: 100%;
  height: 100%;
}

/****************************************
** Screen Switcher
*/

.title-screen,
.game-screen {
  width: 100%;
  height: 100%;
}

body:not(.title-screen-active) .title-screen,
body:not(.game-screen-active) .game-screen {
  display: none;
}

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

.title-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 24px 20px;
  overflow-y: auto;
}

.title-close-button {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-soft);
  box-shadow: 0 4px 10px rgba(30, 41, 59, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.title-close-button:active {
  transform: scale(0.94);
}

body:not(.is-web-page) .title-close-button {
  display: none;
}

.title-close-button img {
  width: 22px;
  height: 22px;
}

.title-content {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.title-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.title-logo-image {
  width: 72px;
  height: 72px;
  display: block;
}

.title-heading {
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink-primary);
  line-height: 1.15;
}

.title-wordmark-image {
  display: block;
  width: min(270px, 72vw);
  height: auto;
  margin: 2px auto 0;
  filter: drop-shadow(0 4px 10px rgba(30, 41, 59, 0.08));
}

.lang-en .title-wordmark-image {
  width: min(310px, 80vw);
}

.title-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.title-options {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 74px;
  padding: 12px 10px;
  border-radius: 18px;
  border: 2px solid var(--border-soft);
  background: var(--surface);
  color: var(--ink-primary);
  cursor: pointer;
  text-align: center;
  box-shadow: 0 4px 0 #DCE4EC;
  transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.mode-option:active {
  transform: translateY(2px);
}

.mode-option-title {
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
}

.mode-option-desc {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

body.mode-tutorial .mode-option-tutorial {
  border-color: var(--accent-mint);
  background: #ECFDF5;
  box-shadow: 0 4px 0 #A7F3D0;
}

body.mode-normal .mode-option-normal {
  border-color: var(--accent-secondary);
  background: #EFF6FF;
  box-shadow: 0 4px 0 #BFDBFE;
}

.stage-input-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.stage-input-toggle {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 2px dashed #CBD5E1;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink-secondary);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

body.stage-input-open .stage-input-toggle {
  display: none;
}

.stage-input-wrap {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid #FDE68A;
}

body:not(.stage-input-open) .stage-input-wrap {
  display: none;
}

.stage-number-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid var(--border-soft);
  font-size: 1.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink-primary);
  background: var(--surface-soft);
  user-select: text;
  -webkit-user-select: text;
}

.stage-number-input::placeholder {
  color: #94A3B8;
  font-weight: 700;
}

.stage-number-input:focus {
  outline: none;
  border-color: var(--accent-secondary);
  background: var(--surface);
}

.stage-input-close {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 2px solid var(--border-soft);
  background: var(--surface-soft);
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.stage-input-close:active {
  transform: scale(0.94);
}

.stage-input-close img {
  width: 20px;
  height: 20px;
}

.title-action-button {
  width: 100%;
  max-width: 260px;
  min-height: 56px;
  padding: 14px 36px;
  border: none;
  border-radius: 28px;
  background: var(--accent-primary);
  color: #FFFFFF;
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 6px 0 var(--accent-primary-dark);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.title-action-button:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--accent-primary-dark);
}

/****************************************
** Game Screen
*/

.game-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  height: 58px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 2px solid rgba(203, 213, 225, 0.65);
  z-index: 5;
}

.stage-status {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--ink-primary);
  white-space: nowrap;
}

.stage-number-value {
  font-variant-numeric: tabular-nums;
}

body.is-tutorial .stage-label-normal,
body:not(.is-tutorial) .stage-label-tutorial {
  display: none;
}

.game-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#canvas-container {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
  touch-action: pinch-zoom;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: pinch-zoom;
}

.sound-button {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--border-soft);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.sound-button:active {
  transform: scale(0.94);
}

.sound-button img {
  width: 20px;
  height: 20px;
}

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

.game-sub-button {
  min-height: 44px;
  padding: 8px 16px;
  border: 2px solid #FECACA;
  background: #FFF5F5;
  color: #DC2626;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.game-sub-button:active {
  transform: scale(0.96);
}

/****************************************
** Popups (Give Up & Stage Clear)
*/

.popup-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
  z-index: 20;
}

body:not(.give-up-popup-open) .give-up-overlay,
body:not(.tutorial-notice-open) .tutorial-notice-overlay,
body:not(.stage-cleared) .stage-clear-overlay {
  display: none;
}

.popup-card {
  width: 100%;
  max-width: 320px;
  padding: 26px 22px;
  border-radius: 24px;
  background: var(--surface);
  border: 3px solid var(--border-soft);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.clear-card {
  border-color: #FDE047;
}

.popup-title {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--ink-primary);
}

.clear-title {
  color: #EA580C;
}

.popup-message {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-secondary);
  line-height: 1.5;
}

.popup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.popup-button {
  width: 100%;
  min-height: 46px;
  padding: 10px 18px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease;
}

.popup-button:active {
  transform: translateY(2px);
}

.popup-button-primary {
  background: var(--accent-mint);
  color: #FFFFFF;
  box-shadow: 0 4px 0 #059669;
}

.popup-button-danger {
  background: var(--accent-primary);
  color: #FFFFFF;
  box-shadow: 0 4px 0 var(--accent-primary-dark);
}

.popup-button-secondary {
  background: var(--surface-soft);
  color: var(--ink-secondary);
  border: 2px solid var(--border-soft);
}

body.clear-process-paused .next-stage-button {
  visibility: hidden;
  pointer-events: none;
}
