:root {
  --bg-dark: #e8ecf0;
  --bg-main: #f5f7fa;
  --accent: #e94560;
  --accent-dim: #c73e54;
  --success: #2d6a8e;
  --text: #2c3e50;
  --text-muted: #5a6c7d;
}

/*
body {
  font-family: 'Segoe UI', 'Yu Gothic', sans-serif;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-main) 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;

}
*/


#app {
  display: flex;
  min-height: 100vh;

  /* もともと body に書いてたものを #app に移す */
  font-family: 'Segoe UI', 'Yu Gothic', sans-serif;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-main) 100%);
  color: var(--text);
  overflow-x: hidden;

  /* ここが重要：ゲーム内の基準文字サイズを 16px にする */
  font-size: 16px;

}

.game-screen.hidden {
  display: none !important;
}

/* ========== タイトル画面 ========== */
#title-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#title-screen.hidden {
  display: none;
}

.title-screen-inner {
  text-align: center;
  max-width: 800px;
}

.title-screen-heading {
  font-size: 1.8em;
  margin: 0 0 8px 0;
}

/* 英語時: 1行目「Enjoy Learning」小さめ、2行目「Ruler & Compass Puzzle」大きい方 */
.title-screen-heading .title-heading-line1 {
  font-size: 0.75em;
}

.title-screen-sub {
  margin: 0 0 28px 0;
  color: var(--text-muted);
}

.title-section {
  margin-bottom: 24px;
}

.title-section-heading {
  font-size: 1em;
  margin: 0 0 12px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
  color: var(--text-muted);
}

.title-stage-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.title-stage-buttons--cards .stage-btn {
  position: relative;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
}

.title-stage-buttons--cards .stage-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.2);
  background: rgba(0, 0, 0, 0.04);
}

.title-stage-buttons--cards .stage-btn.current {
  background: #fff;
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text);
}

.title-stage-buttons--cards .stage-btn.cleared {
  background: rgba(46, 125, 74, 0.12);
  border-color: rgba(46, 125, 74, 0.45);
  color: #1a5c38;
  box-shadow: 0 2px 8px rgba(46, 125, 74, 0.12);
}

.title-stage-buttons--cards .stage-btn.cleared:hover {
  border-color: rgba(46, 125, 74, 0.6);
  background: rgba(46, 125, 74, 0.18);
  box-shadow: 0 4px 12px rgba(46, 125, 74, 0.18);
}

.title-stage-buttons--cards .stage-btn .stage-clear-icon {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 18px;
  color: #2e7d4a;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

.title-stage-buttons--cards .stage-btn.cleared .stage-clear-icon {
  opacity: 1;
}

.title-stage-buttons--cards .stage-btn .stage-num {
  display: block;
  line-height: 1;
}

.title-btn-start {
  padding: 12px 28px;
  font-size: 1.1em;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  margin-bottom: 28px;
  transition: background 0.2s;
}

.title-btn-start:hover {
  background: var(--accent-dim);
}

.tool-explanation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tool-explanation {
  display: flex;
  align-items: flex-start;
  gap: 4px 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

.tool-explanation-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  object-fit: contain;
}

/* ツール名：左揃え・固定幅で縦の位置を揃える */
.tool-explanation-name {
  width: 5.5em;
  min-width: 5.5em;
  flex-shrink: 0;
  text-align: left;
}

/* … の位置を縦に揃える */
.tool-explanation-dots {
  flex-shrink: 0;
  width: 1.2em;
  text-align: right;
}

/* 説明文：…より右で左揃え、折り返しも左揃え */
.tool-explanation-desc {
  flex: 1;
  min-width: 0;
  text-align: left;
}

/* ツールバー：共通レイアウト（クラス未指定時はこの見た目） */
#toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* パターンA: ピル（角丸・背景のみ・枠線ほぼなし） */
#toolbar.toolbar--pill {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* パターンB: 下線アクセント */
#toolbar.toolbar--underline {
  background: #fff;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* パターンC: 左縁アクセント（縦ライン） */
#toolbar.toolbar--left-accent {
  background: #fff;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-left: 4px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* パターンD: 二重線・額縁風 */
#toolbar.toolbar--double {
  background: #fff;
  border-radius: 8px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  outline: 1px solid rgba(0, 0, 0, 0.06);
  outline-offset: 2px;
  box-shadow: none;
}

/* パターンE: ソフトカード（薄いグレー背景・軽い枠） */
#toolbar.toolbar--soft {
  background: rgba(248, 249, 251, 0.98);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.toolbar-sep {
  width: 1px;
  height: 28px;
  background: rgba(0, 0, 0, 0.15);
  margin: 0 4px;
  flex-shrink: 0;
}

/* スマホ・iPhone：ツールバーを1行に保ち、改行しない */
@media (max-width: 480px) {
  #toolbar {
    flex-wrap: nowrap;
    justify-content: center;
    padding: 10px 12px;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #toolbar::-webkit-scrollbar {
    display: none;
  }
  #toolbar .tool-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }
  #toolbar .tool-btn .tool-icon {
    width: 22px;
    height: 22px;
  }
  #toolbar #tool-undo .tool-icon {
    width: 26px;
    height: 26px;
  }
  #toolbar .toolbar-sep {
    height: 24px;
    margin: 0 2px;
    flex-shrink: 0;
  }
}

.tool-btn {
  width: 44px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tool-btn .tool-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

#tool-undo .tool-icon {
  width: 32px;
  height: 32px;
}

.tool-btn.active .tool-icon {
  filter: brightness(0) invert(1);
}

.tool-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
  background: var(--accent);
  border-color: rgba(255, 255, 255, 0.5);
  color: white;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
}

#stage-header {
  margin-bottom: 12px;
}

#stage-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

#stage-nav .btn-back-to-title {
  width: auto;
  height: auto;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

#stage-nav .btn-back-to-title:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.06);
}

#stage-nav button:not(.btn-back-to-title) {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

#stage-nav button:hover {
  background: rgba(0, 0, 0, 0.06);
}

#stage-display {
  font-size: 15px;
  color: var(--text-muted);
}

.stage-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 0;
}

#stage-title {
  font-size: 1.6em;
  font-weight: 600;
  margin: 0;
}

.stage-conditions-hidden {
  display: none !important;
}

.tool-btn--header {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.tool-btn--header .tool-icon {
  width: 20px;
  height: 20px;
}

.cuts-remaining-row {
  flex-basis: 100%;
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.cuts-remaining-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  flex-basis: auto;
  width: auto;
  margin-top: 0;
  padding: 8px 12px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cuts-remaining-overlay.hidden {
  display: none;
}

.cuts-remaining-label {
  flex-shrink: 0;
}

#cuts-remaining-icons {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#cuts-remaining-icons .cut-icon {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

#cuts-remaining-icons .cut-icon.cut-icon-used {
  filter: grayscale(1);
  opacity: 0.22;
}

#stage-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  font-size: 16px;
  color: var(--text-muted);
}

.stage-condition {
  display: inline-block;
}

.compass-unlock-btn {
  padding: 4px 10px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.compass-unlock-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.compass-unlock-btn.hidden {
  display: none;
}

/* 解除は問題画面右上のバッジで行うため、ヘッダーの解除ボタンは常に非表示 */
#compass-unlock {
  display: none !important;
}

/* キャンバスはツールバー直下から表示（中央寄せしない） */
#canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 300px;
}

#canvas-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1; /* 正方形（キャンバスに合わせる） */
  max-height: 100%;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.compass-lock-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(233, 69, 96, 0.14);
  border: 1px solid rgba(233, 69, 96, 0.5);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dim);
  box-shadow: 0 2px 8px rgba(233, 69, 96, 0.2);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  pointer-events: auto;
}

.compass-lock-badge:hover {
  background: rgba(233, 69, 96, 0.22);
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(233, 69, 96, 0.3);
}

.compass-lock-badge.hidden {
  display: none;
}

.compass-lock-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
}

.compass-lock-text {
  white-space: nowrap;
}

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

#clear-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  transition: background 0.6s ease-out;
  animation: clearFadeIn 0.5s ease-out;
}

#clear-overlay.reveal {
  background: rgba(255, 255, 255, 0.42);
}

#clear-overlay.hidden {
  display: none;
}

#clear-content {
  position: absolute;
  inset: 0;
}

#clear-text-wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.9s cubic-bezier(0.22, 0.61, 0.36, 1);
}

#clear-overlay.reveal #clear-text-wrapper {
  transform: translate(-50%, -50%) translateY(-100px);
}

#clear-text {
  font-size: 3em;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(233, 69, 96, 0.6);
}

#btn-next-stage {
  position: absolute;
  top: calc(50% + 125px);
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  font-size: 1em;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

#btn-next-stage:hover:not(:disabled) {
  background: var(--accent-dim);
}

#btn-next-stage:disabled {
  opacity: 0.7;
  cursor: default;
}

@keyframes clearFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#stage-selector {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#stage-label {
  font-size: 13px;
  color: var(--text-muted);
}

#stage-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-btn {
  position: relative;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-btn .stage-num {
  display: block;
}

.stage-btn .stage-clear-icon {
  display: none;
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 10px;
  color: #2e7d4a;
}

.stage-btn.cleared .stage-clear-icon {
  display: block;
}

.stage-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.stage-btn.cleared {
  background: rgba(46, 125, 74, 0.15);
  border-color: rgba(46, 125, 74, 0.5);
}

.stage-btn.cleared .stage-num {
  color: #2e7d4a;
}

.stage-btn.current {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

.stage-btn.current .stage-clear-icon {
  color: #2e7d4a;
}

#debug-panel {
  margin-top: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-muted);
  max-height: 120px;
  overflow-y: auto;
}

#debug-info {
  white-space: pre-wrap;
  word-break: break-all;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #ffffff;
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
  margin-bottom: 12px;
}

.modal-content p {
  margin-bottom: 16px;
  line-height: 1.6;
}

#hint-close {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
}

#hint-close:hover {
  background: var(--accent-dim);
}
