/* =============================
  リセットCSS・基本設定
============================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background-color: #f5e6e8;
  font-family: 'Cormorant Garamond', serif;
  color: #8B4513;
  min-width: 0;
  overflow-x: hidden;
}

ul {
  list-style: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

img {
  display: block;
  max-width: 100%;
}

/* =============================
  ヘッダー
============================== */

.header {
  width: 100%;
  max-width: 1440px;
  height: auto;
  min-height: 80px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo img,
.header-timer img {
  width: clamp(40px, 10vw, 60px);
  height: clamp(40px, 10vw, 60px);
  object-fit: contain;
}

.header-title {
  font-family: 'Bodoni Moda SC', serif;
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 400;
  letter-spacing: 0.05em;
  color: #8B4513;
}

.header-timer {
  display: flex;
  align-items: center;
  gap: 16px;
}

.timer-display {
  font-family: 'Bodoni Moda SC', serif;
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 400;
  letter-spacing: 0.05em;
  color: #8B4513;
}

/* =============================
  メインエリア
============================== */

.main {
  width: 100%;
  max-width: 1440px;
  margin: 40px auto 48px;
  padding: 0 24px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 40px;
}

.board-wrap {
  width: 100%;
  max-width: 675px;
  flex: 1 1 675px;
}

.panel {
  width: 100%;
  max-width: 453px;
  flex: 1 1 453px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding-top: 20px;
  position: relative;
}

.panel-controls {
  display: contents;
}

/* =============================
  ゲーム盤面
============================== */

.board {
  width: 100%;
  aspect-ratio: 675 / 681;
  height: auto;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 4px solid #8B4513;
  box-sizing: border-box;
  border-radius: 4px;
  box-shadow:
    4px 4px 8px rgba(180,130,140,0.3),
    -2px -2px 6px rgba(255,255,255,0.8);
  overflow: hidden;
  position: relative;
}

.start-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(250, 243, 208, 0.85);
  z-index: 10;
}

.start-title {
  font-family: 'Bodoni Moda SC', serif;
  font-size: clamp(32px, 8vw, 64px);
  color: #8B4513;
  letter-spacing: 0.1em;
}

.start-sub {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(16px, 4vw, 28px);
  color: #a07860;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 0 16px;
}

/* =============================
  マス目
============================== */

.cell {
  background-color: #faf3d0;
  border: 1px solid #8B4513;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bodoni Moda SC', serif;
  font-size: clamp(14px, 3.5vw, 28px);
  cursor: pointer;
  transition: background-color 0.15s;
}

.cell:hover {
  background-color: #f2e5b0;
}

.cell.border-right {
  border-right: 4px solid #8B4513;
}

.cell.border-bottom {
  border-bottom: 4px solid #8B4513;
}

.cell.selected {
  background-color: #e8d5a3;
}

.cell.highlight {
  background-color: #f2eccc;
}

.cell.preset {
  color: #8B4513;
  font-weight: 600;
}

.cell.user-input {
  color: #4169e1 !important;
  font-weight: 600 !important;
}

.cell.error {
  background-color: #fde8e8;
  color: #c0392b !important;
  font-weight: 400;
}

/* =============================
  メモ
============================== */

.memo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 3px;
  box-sizing: border-box;
}

.memo-grid span {
  font-size: clamp(8px, 2vw, 14px);
  color: #a07860;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* =============================
  クリア表示
============================== */

.clear-area {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-top: 40px;
  text-align: center;
  font-size: clamp(18px, 4vw, 24px);
}

.clear-area.show {
  display: flex;
}

/* =============================
  難易度選択
============================== */

.difficulty {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 24px;
  width: 100%;
}

.difficulty-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Bodoni Moda SC', serif;
  font-size: 22px;
  color: #8B4513;
  cursor: pointer;
}

.difficulty-item input[type="radio"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

/* =============================
  START・一時停止・消しゴムボタン
============================== */

.btn-row {
  display: flex;
  gap: 16px;
  width: 100%;
}

.btn {
  flex: 1;
  height: 52px;
  border-radius: 16px;
  font-family: 'Bodoni Moda SC', serif;
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: #8B4513;
  cursor: pointer;
  transition: transform 0.12s;
  background: linear-gradient(145deg, #fdf0f2, #e8d0d4);
  border: 1px solid #d4b0b8;
  box-shadow:
    4px 4px 8px rgba(180,130,140,0.3),
    -2px -2px 6px rgba(255,255,255,0.8);
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px);
  box-shadow:
    2px 2px 4px rgba(180,130,140,0.3),
    -1px -1px 3px rgba(255,255,255,0.8);
}

/* =============================
  数字ボタン
============================== */

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.num-btn {
  width: 100%;
  height: 62px;
  border-radius: 16px;
  font-family: 'Bodoni Moda SC', serif;
  font-size: 24px;
  font-weight: 400;
  color: #8B4513;
  cursor: pointer;
  transition: transform 0.1s;
  background: linear-gradient(145deg, #fdf0f2, #e8d0d4);
  border: 1px solid #d4b0b8;
  box-shadow:
    4px 4px 8px rgba(180,130,140,0.3),
    -2px -2px 6px rgba(255,255,255,0.8);
}

.num-btn.grayed-out {
  color: #bbb;
  cursor: not-allowed;
}

.num-btn:hover {
  transform: scale(1.05);
}

.num-btn:active {
  transform: scale(0.95);
  box-shadow:
    2px 2px 4px rgba(180,130,140,0.3),
    -1px -1px 3px rgba(255,255,255,0.8);
}

/* =============================
  ヒントボタン
============================== */

.hint-row {
  width: 100%;
  margin-top: 24px;
}

.btn-hint {
  width: 100%;
  height: 52px;
}

.btn-hint:disabled {
  color: #bbb;
  cursor: not-allowed;
  opacity: 0.6;
}

/* =============================
  花の配置
============================== */

.flower {
  position: absolute;
  pointer-events: none;
}

.flower-right {
  top: -20px;
  right: -20px;
  width: 120px;
}

.flower-left {
  top: 365px;
  left: -20px;
  width: 120px;
}

/* =============================
  操作ガイド
============================== */

.guide {
  width: 100%;
  margin-top: 8px;
}

.guide-title {
  font-family: 'Bodoni Moda SC', serif;
  font-size: 20px;
  font-weight: 400;
  color: #8B4513;
  margin-bottom: 12px;
}

.guide-subtitle {
  font-family: 'Bodoni Moda SC', serif;
  font-size: 16px;
  font-weight: 400;
  color: #8B4513;
  margin-bottom: 8px;
}

.guide-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guide-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-list li {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(13px, 3.2vw, 14px);
  color: #8B4513;
  line-height: 1.6;
}

/* =============================
  レスポンシブ
============================== */

@media (max-width: 1024px) {
  .main {
    flex-wrap: wrap;
    margin-top: 32px;
    gap: 32px;
  }

  .board-wrap,
  .panel {
    flex: 1 1 100%;
    max-width: 560px;
    margin: 0 auto;
  }

  .panel {
    padding-top: 0;
  }

  .flower-left {
    top: auto;
    bottom: 120px;
  }
}

@media (max-width: 768px) {
  :root {
    --mobile-header: 60px;
    --mobile-controls: 240px;
  }

  .header {
    padding: 10px 16px;
    min-height: var(--mobile-header);
  }

  .header-logo {
    gap: 10px;
  }

  .header-timer {
    gap: 8px;
  }

  .main {
    margin-top: 8px;
    margin-bottom: 0;
    padding: 0 12px;
    gap: 16px;
    padding-bottom: calc(var(--mobile-controls) + env(safe-area-inset-bottom, 0px) + 12px);
  }

  .board-wrap {
    max-width: min(100%, calc(100dvh - var(--mobile-header) - var(--mobile-controls) - 24px));
    margin: 0 auto;
  }

  .board {
    width: 100%;
    max-height: calc(100dvh - var(--mobile-header) - var(--mobile-controls) - 24px);
    aspect-ratio: 1;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    padding-top: 0;
    gap: 0;
    align-items: stretch;
  }

  .panel-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, #f5e6e8 90%, rgba(245, 230, 232, 0.95));
    box-shadow: 0 -4px 16px rgba(139, 69, 19, 0.1);
  }

  .difficulty {
    gap: 6px 12px;
  }

  .difficulty-item {
    font-size: 14px;
  }

  .difficulty-item input[type="radio"] {
    width: 16px;
    height: 16px;
  }

  .btn-row {
    gap: 8px;
  }

  .btn {
    height: 40px;
    font-size: 14px;
    border-radius: 12px;
  }

  .numpad {
    gap: 6px;
  }

  .num-btn {
    height: 40px;
    font-size: 18px;
    border-radius: 10px;
  }

  .hint-row {
    margin-top: 0;
  }

  .btn-hint {
    height: 40px;
  }

  .flower-right,
  .flower-left {
    display: none;
  }

  .guide {
    margin-top: 8px;
    padding-bottom: 16px;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-controls: 228px;
  }

  .header-title {
    font-size: 20px;
  }

  .timer-display {
    font-size: 20px;
  }
}

@media (min-width: 1440px) {
  .header {
    padding: 0 136px;
    min-height: 100px;
  }

  .main {
    margin-top: 120px;
    padding: 0 136px;
  }
}