:root {
  --ink: #221d29;
  --ink-muted: #675f73;
  --cream: #fcf8ef;
  --paper: #f5efe2;
  --red: #e53935;
  --red-dark: #b32420;
  --blue: #2673eb;
  --gold: #e6a117;
  --green: #269966;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "PingFang SC", "Apple SD Gothic Neo", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.hidden {
  display: none !important;
}

/* 共通カスタムアイコンボタン */
.game-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.game-icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

/* プレイ中HUD */
#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
}

.stage-chip {
  display: inline-flex;
  align-items: center;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 3px 0 var(--ink);
}

.chip-mode {
  background: var(--ink);
  color: var(--cream);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 6px 9px;
}

.chip-num {
  font-size: 13px;
  font-weight: 900;
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hud-title-block {
  text-align: center;
  min-width: 0;
  width: 100%;
}

.target-name {
  font-size: clamp(15px, 3.8vw, 21px);
  font-weight: 900;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.target-rule {
  font-size: clamp(10.5px, 2.5vw, 13px);
  font-weight: 700;
  color: var(--ink-muted);
  line-height: 1.3;
}

.hearts-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.heart-svg {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 2px 0 rgba(34, 29, 41, 0.25));
}

.mode-tag-pill {
  font-size: 11px;
  font-weight: 900;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(34, 29, 41, 0.08);
  color: var(--ink);
}

.score-plate {
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 3px 12px;
  box-shadow: 0 3px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
}

.score-tag {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.score-digits {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* タクタイルなゲームボタン共通 */
.tactile-btn {
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.tactile-btn:active {
  transform: translateY(3px);
}

.tactile-btn.play-main {
  width: 100%;
  padding: 13px 22px;
  background: linear-gradient(180deg, #f24844 0%, #dc312d 100%);
  color: #fffdf8;
  box-shadow: 0 5px 0 var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 2px 10px;
}

.tactile-btn.play-main:active {
  box-shadow: 0 2px 0 var(--ink);
}

.btn-main-label {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.btn-sub-tag {
  font-size: 12px;
  font-weight: 800;
  opacity: 0.9;
  letter-spacing: 0.05em;
}

.tactile-btn.sub-mode {
  background: var(--cream);
  color: var(--ink);
  padding: 10px 10px;
  box-shadow: 0 4px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.tactile-btn.sub-mode:active {
  box-shadow: 0 1px 0 var(--ink);
}

.sub-title {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.sub-title em {
  font-style: normal;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--cream);
  white-space: nowrap;
}

.sub-caption {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 切断後のNEXTバー */
.next-bar {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
  z-index: 15;
}

.tactile-btn.next {
  background: var(--ink);
  color: var(--cream);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 0 var(--red);
  animation: popIn 0.22s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.82) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* タイトル画面（上下セパレートで中央デモをそのまま見せる） */
.title-layout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 18px max(22px, calc(env(safe-area-inset-bottom) + 14px));
  z-index: 18;
  pointer-events: none;
}

.title-top {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.title-top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  pointer-events: auto;
}

.title-top-left {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.hub-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--cream);
  color: var(--ink);
  text-decoration: none;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: 0.03em;
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.hub-link:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}

.title-top-right {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.title-top-bar #lang-select.ma-lang-select {
  height: 40px;
  min-width: 58px;
  max-width: 90px;
  padding: 0 20px 0 10px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background-color: var(--cream);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  font-size: 11.5px;
  font-weight: 900;
}

.best-pill {
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-lockup {
  max-width: 100%;
  text-align: center;
  background: rgba(252, 248, 239, 0.86);
  padding: 8px 24px 10px;
  border-radius: 20px;
  border: 2px solid rgba(34, 29, 41, 0.12);
}

.logo-main {
  font-size: clamp(38px, 8.5vw, 54px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 rgba(34, 29, 41, 0.14);
}

.num-50.red {
  color: var(--red);
}

.num-50.blue {
  color: var(--blue);
}

.slash-mark {
  display: inline-block;
  margin: 0 3px;
  color: var(--ink);
  transform: rotate(10deg);
}

.cut-stamp {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 11px;
  background: var(--ink);
  color: var(--cream);
  border-radius: 10px;
  font-size: 0.62em;
  vertical-align: middle;
  transform: rotate(-4deg);
  box-shadow: 0 3px 0 var(--red);
}

.logo-tagline {
  margin: 6px 0 0;
  font-size: clamp(11.5px, 3.4vw, 13px);
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink-muted);
  word-break: normal;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.logo-tagline strong {
  color: var(--ink);
}

.title-bottom {
  width: min(390px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.sub-modes-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* リザルト画面 */
.result-overlay {
  position: absolute;
  inset: 0;
  background: rgba(34, 29, 41, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 25;
}

.result-board {
  width: min(410px, 100%);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 22px;
  padding: 22px 20px 18px;
  box-shadow: 0 8px 0 var(--ink);
  text-align: center;
  animation: popIn 0.24s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.result-ribbon {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.result-title {
  margin: 8px 0 14px;
  font-size: 25px;
  font-weight: 900;
}

.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.metric-box {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 13px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-box.highlight {
  background: #fff6e8;
}

.metric-label {
  font-size: 10px;
  font-weight: 900;
  color: var(--ink-muted);
}

.metric-val {
  font-size: 19px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.metric-box.highlight .metric-val {
  color: var(--red);
}

.cut-log-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 130px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 10px;
  border-radius: 9px;
  background: rgba(34, 29, 41, 0.05);
}

.log-item .log-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.log-item .log-val {
  flex-shrink: 0;
  white-space: nowrap;
}

.grade-tag {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  color: #fff;
}

.result-btns {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.result-sub-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.copy-toast {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 900;
  color: var(--green);
}

@media (max-width: 560px) {
  #hud {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px 4px;
  }
  .hud-side {
    gap: 5px;
  }
  .game-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }
  .chip-mode {
    display: none;
  }
  .chip-num {
    font-size: 12px;
    padding: 5px 8px;
  }
  .heart-svg {
    width: 16px;
    height: 16px;
  }
  .hearts-row {
    gap: 2px;
  }
  .score-plate {
    padding: 2px 8px;
    border-radius: 10px;
  }
  .score-digits {
    font-size: 14px;
  }
  .hud-title-block {
    flex: 0 0 100%;
    order: 3;
    margin-top: 0;
  }
  .logo-lockup {
    padding: 8px 14px 10px;
  }
  .title-top-bar #lang-select.ma-lang-select {
    height: 34px;
    min-width: 54px;
    max-width: 80px;
    padding: 0 16px 0 8px;
    border-radius: 10px;
    font-size: 10.5px;
  }
  .title-top-right {
    gap: 5px;
  }
}

@media (max-width: 420px) {
  .title-layout {
    padding: max(10px, env(safe-area-inset-top)) 10px max(16px, calc(env(safe-area-inset-bottom) + 10px));
  }
  .best-pill {
    padding: 5px 10px;
    font-size: 11px;
  }
  .logo-lockup {
    padding: 7px 12px 9px;
    border-radius: 16px;
  }
  .logo-tagline {
    font-size: 11px;
  }
  .tactile-btn.play-main {
    padding: 11px 16px;
  }
  .btn-main-label {
    font-size: 20px;
  }
  .btn-sub-tag {
    font-size: 11px;
  }
  .tactile-btn.sub-mode {
    padding: 8px 6px;
  }
  .sub-title {
    font-size: 12.5px;
    gap: 4px;
  }
  .sub-title em {
    font-size: 10px;
    padding: 1.5px 5px;
  }
  .sub-caption {
    font-size: 10px;
  }
  .result-board {
    padding: 16px 14px 14px;
  }
  .result-title {
    font-size: 20px;
  }
  .metric-val {
    font-size: 16px;
  }
}

@media (max-width: 340px) {
  .title-layout {
    padding: max(10px, env(safe-area-inset-top)) 8px max(14px, calc(env(safe-area-inset-bottom) + 10px));
  }
  .title-top-bar {
    gap: 5px;
  }
  .title-top-right {
    gap: 4px;
  }
  .title-top-bar #lang-select.ma-lang-select {
    height: 32px;
    min-width: 48px;
    max-width: 72px;
    padding: 0 14px 0 6px;
    font-size: 10px;
  }
  .game-icon-btn {
    width: 32px;
    height: 32px;
  }
  .hud-side {
    gap: 4px;
  }
  .chip-num {
    font-size: 11px;
    padding: 4px 6px;
  }
  .mode-tag-pill {
    font-size: 9.5px;
    padding: 4px 6px;
  }
  .score-plate {
    padding: 2px 6px;
  }
  .score-digits {
    font-size: 13px;
  }
  .heart-svg {
    width: 14px;
    height: 14px;
  }
  .best-pill {
    padding: 4px 8px;
    font-size: 10px;
  }
  .title-top-left {
    gap: 4px;
  }
  .hub-link {
    padding: 4px 7px;
    font-size: 10px;
    gap: 3px;
  }
  .hub-link svg {
    width: 12px;
    height: 12px;
  }
  .logo-main {
    font-size: 32px;
  }
  .btn-main-label {
    font-size: 18px;
  }
  .sub-title {
    font-size: 11.5px;
  }
  .sub-title em {
    font-size: 9px;
    padding: 1px 4px;
  }
  .sub-caption {
    font-size: 9.5px;
  }
  .result-title {
    font-size: 18px;
    line-height: 1.25;
  }
  .log-item {
    font-size: 11px;
  }
}
