/* ==========================================
   漢字スナイパー CSS
   プレフィックス: ks-
   ========================================== */

/* === CSS変数定義 === */
.ks-wrap {
  --base: #FFFFFF;
  --base-light: #FAFAFA;
  --base-dark: #F5F5F5;
  --main: #1e3a5f;
  --main-light: #2d5a8f;
  --main-dark: #0f1e3a;
  --accent: #d4af37;
  --accent-light: #f4cf5f;
  --accent-dark: #b8941f;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --border: #E8E8E8;
  --shadow: 0 4px 20px rgba(30, 58, 95, 0.1);
  --shadow-hover: 0 8px 30px rgba(30, 58, 95, 0.15);
}

/* === リセット === */
.ks-wrap * {
  box-sizing: border-box;
}

/* === ベースレイアウト === */
.ks-wrap {
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(12px, 2vw, 20px);
  background: linear-gradient(135deg, #FFFFFF 0%, #F8F9FA 50%, #F0F2F5 100%);
  min-height: 100vh;
}

/* 2カラムレイアウト（先生画面用） */
@media (min-width: 900px) {
  .ks-wrap {
    max-height: 100vh;
    overflow: hidden;
  }
}

/* === ヘッダー === */
.ks-header {
  background: var(--main);
  border-top: 3px solid var(--accent);
  border-bottom: 3px solid var(--accent);
  border-radius: 20px;
  padding: clamp(16px, 2.5vh, 24px);
  margin-bottom: clamp(16px, 3vh, 24px);
  box-shadow: 0 4px 20px rgba(30, 58, 95, 0.3);
  text-align: center;
}

.ks-header h1 {
  color: #ffffff;
  font-weight: 900;
  font-size: clamp(24px, 4vw, 36px);
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* === パネル === */
.ks-panel {
  background: var(--base);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: clamp(16px, 2.5vw, 28px);
  box-shadow: var(--shadow);
  position: relative;
  margin-bottom: clamp(12px, 2vh, 20px);
}

.ks-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
  border-radius: 24px 24px 0 0;
}

.ks-panel h2 {
  color: var(--main);
  font-weight: 900;
  font-size: clamp(18px, 3vw, 24px);
  margin: 0 0 clamp(12px, 2vh, 16px);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ks-panel h2::before {
  content: '';
  width: 6px;
  height: 24px;
  background: var(--accent);
  border-radius: 3px;
  flex-shrink: 0;
}

/* === ボタン === */
.ks-btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: clamp(12px, 2vh, 16px) clamp(16px, 3vw, 24px);
  font-weight: 900;
  font-size: clamp(16px, 2.5vw, 20px);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  display: block;
}

.ks-btn-primary {
  background: linear-gradient(135deg, var(--main-light) 0%, var(--main) 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

.ks-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--main) 0%, var(--main-dark) 100%);
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.ks-btn-secondary {
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
  color: var(--main-dark);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.ks-btn-secondary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(212, 175, 55, 0.4);
}

.ks-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* === 入力フィールド === */
.ks-input {
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: clamp(12px, 2vh, 16px);
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 600;
  background: var(--base);
  color: var(--text);
  outline: none;
  transition: all 0.3s ease;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  display: block;
}

.ks-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.15);
  transform: scale(1.02);
}

.ks-input:hover {
  border-color: var(--main-light);
}

/* === 漢字選択チップ === */
.ks-kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
  padding: 8px;
  background: var(--base-light);
  border-radius: 16px;
}

.ks-kanji-chip {
  border: 2px solid var(--border);
  background: var(--base);
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  font-weight: 900;
  font-size: clamp(20px, 3vw, 28px);
  text-align: center;
  color: var(--text);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ks-kanji-chip:hover {
  border-color: var(--accent);
  background: #fffcf5;
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.2);
}

.ks-kanji-chip.active {
  border-color: var(--main);
  background: var(--main);
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(30, 58, 95, 0.35);
  transform: scale(1.05);
}

/* === ゲーム画面（9分割パネル） === */
.ks-game-fullscreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #FFFFFF 0%, #F8F9FA 100%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vh, 32px);
}

.ks-game-header {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: clamp(16px, 3vh, 24px);
  flex-wrap: wrap;
}

.ks-pill {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--main);
  color: #fff;
  font-weight: 900;
  font-size: clamp(16px, 2.5vw, 20px);
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.2);
}

.ks-pill strong {
  color: var(--accent);
  font-size: clamp(20px, 3vw, 28px);
}

.ks-grid-container {
  position: relative;
  width: min(90vmin, 500px);
  aspect-ratio: 1/1;
}

.ks-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  width: 100%;
  height: 100%;
  perspective: 1200px;
}

.ks-cell {
  position: relative;
  transform-style: preserve-3d;
  border: 2px solid var(--main);
}

.ks-kanji-bg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'UD デジタル 教科書体 N-R', 'UD Digi Kyokasho N-R', 'ヒラギノ明朝 ProN', 'Hiragino Mincho ProN', '游明朝', 'Yu Mincho', 'MS 明朝', 'MS Mincho', serif;
  font-size: min(70vmin, 400px);
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.ks-cover {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, var(--main) 0%, var(--main-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: clamp(32px, 8vmin, 64px);
  user-select: none;
  cursor: pointer;
  transform-origin: left center;
  backface-visibility: hidden;
  transform: rotateY(0deg);
  transition: transform 0.3s ease, opacity 0.2s ease;
  box-shadow: inset 0 0 0 2px rgba(212, 175, 55, 0.3);
  z-index: 2;
}

.ks-cover:hover {
  background: linear-gradient(145deg, var(--main-light) 0%, var(--main) 100%);
}

.ks-cover.open {
  transform: rotateY(-90deg);
  opacity: 0;
  pointer-events: none;
}

.ks-cover.locked {
  background: linear-gradient(145deg, #4b5563 0%, #374151 100%);
  cursor: not-allowed;
}

/* === 結果画面 === */
.ks-result-fullscreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #FFFFFF 0%, #F8F9FA 100%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vh, 32px);
  overflow-y: auto;
}

.ks-result-panel {
  background: var(--base);
  border: 3px solid var(--accent);
  border-radius: 24px;
  padding: clamp(20px, 4vh, 32px);
  max-width: 600px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(30, 58, 95, 0.15);
}

.ks-result-value {
  font-size: clamp(48px, 10vw, 96px);
  font-weight: 900;
  background: linear-gradient(135deg, var(--main) 0%, var(--main-light) 50%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin: clamp(16px, 3vh, 24px) 0;
}

/* === ユーティリティ === */
.ks-text-center {
  text-align: center;
}

.ks-mb-16 {
  margin-bottom: 16px;
}

.ks-mb-24 {
  margin-bottom: 24px;
}

.ks-hint {
  font-size: clamp(12px, 1.8vw, 14px);
  color: var(--text-light);
  padding: 10px 16px;
  background: var(--base-dark);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  line-height: 1.6;
  margin: 12px 0;
}

.ks-hint strong {
  color: var(--main);
  font-weight: 900;
}

.ks-select {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font-size: clamp(14px, 2vw, 16px);
  font-weight: 600;
  background: var(--base);
  color: var(--text);
  width: 100%;
  outline: none;
  margin-bottom: 12px;
}

.ks-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

.ks-close-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  background: var(--main);
  color: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.ks-close-btn:hover {
  background: var(--accent);
  color: var(--main);
  transform: rotate(90deg) scale(1.1);
}

/* === QRコード === */
.ks-qr-container {
  text-align: center;
  padding: 20px;
  background: var(--base-light);
  border-radius: 16px;
  border: 2px dashed var(--accent);
}

.ks-qr-container img {
  max-width: 200px;
  height: auto;
  border: 3px solid var(--main);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(30, 58, 95, 0.2);
}

/* === レスポンシブ === */
@media (max-width: 600px) {
  .ks-kanji-grid {
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  }
  
  .ks-kanji-chip {
    font-size: 20px;
    min-height: 50px;
  }
}
