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

:root {
  --shirt-color: #4A90D9;
  --beer-color:  #F5A623;
  --bg:          #1a1a2e;
  --surface:     #16213e;
  --surface2:    #0f3460;
  --text:        #e8e8e8;
  --text-sub:    #a0a0b0;
  --border:      #2a2a4a;
  --error:       #e74c3c;
  --success:     #2ecc71;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ===== ヘッダー ===== */
header {
  padding: 20px 0 16px;
  text-align: center;
}

.header-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.btn-howto {
  justify-self: start;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-sub);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-howto:active { opacity: 0.7; }

.btn-lang {
  justify-self: end;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-sub);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-lang:active { opacity: 0.7; }

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--shirt-color), var(--beer-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 8px;
}

.legend {
  font-size: 0.75rem;
  color: var(--text-sub);
}

.legend .s { color: var(--success);    font-weight: 700; }
.legend .b { color: var(--beer-color); font-weight: 700; }

/* ===== ゲームエリア ===== */
#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 8px;
}

/* ===== 入力表示 ===== */
#input-display {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.digit-box {
  width: 72px;
  height: 80px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-sub);
  transition: border-color 0.15s, color 0.15s;
}

.digit-box.filled {
  border-color: var(--shirt-color);
  color: var(--text);
}

/* ===== ボタン共通 ===== */
#action-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn {
  flex: 1;
  padding: 14px 8px;
  border: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--shirt-color), #2980b9);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-sub);
  border: 1.5px solid var(--border);
}

/* ===== 数字パッド ===== */
#numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
}

.num-btn {
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
}

.num-btn:hover  { background: var(--surface2); }
.num-btn:active { transform: scale(0.93); }

/* ===== 履歴 ===== */
#history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
}

.history-guess {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.4em;
}

.history-result {
  font-size: 0.95rem;
  min-width: 70px;
  text-align: right;
}

.strike-num { color: var(--success);    font-weight: 700; }
.ball-num   { color: var(--beer-color); font-weight: 700; }
.result-open { color: var(--beer-color); font-weight: 700; font-size: 1rem; }

/* ===== メモエリア ===== */
#memo-area {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.memo-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 12px;
}

.memo-sub-label {
  font-size: 0.75rem;
  color: var(--text-sub);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.memo-hint-text {
  font-size: 0.68rem;
  color: var(--border);
}

.chip-out-eg { color: var(--error);   font-weight: 600; }
.chip-in-eg  { color: var(--beer-color); font-weight: 600; }

/* 数字チップ */
#digit-chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.digit-chip {
  width: 100%;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, opacity 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.digit-chip:active { transform: scale(0.92); }

/* ✕ない */
.digit-chip.state-out {
  border-color: var(--error);
  background: rgba(231,76,60,0.1);
  color: var(--error);
  text-decoration: line-through;
  opacity: 0.6;
}

/* ◯どこかにある */
.digit-chip.state-in {
  border-color: var(--beer-color);
  background: rgba(245,166,35,0.15);
  color: var(--beer-color);
}

/* 位置メモ */
#pos-slots {
  display: flex;
  gap: 10px;
}

.pos-slot {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.pos-slot:active { transform: scale(0.95); }

.pos-slot.state-possible {
  border-color: var(--beer-color);
}

.pos-slot.state-confirmed {
  border-color: var(--success);
}

.pos-label {
  font-size: 0.7rem;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.pos-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-sub);
}

.pos-slot.state-possible .pos-value { color: var(--beer-color); }
.pos-slot.state-confirmed .pos-value { color: var(--success); }

/* ===== モーダル共通 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0 16px 16px;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: 24px 24px 16px 16px;
  padding: 32px 24px 24px;
  width: 100%;
  max-width: 448px;
  text-align: center;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  animation: slideUp 0.3s ease;
  position: relative;
}

@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.result-emoji { font-size: 3.5rem; margin-bottom: 8px; }

.modal-content h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--shirt-color), var(--beer-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-content p {
  color: var(--text-sub);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.secret-reveal { margin-bottom: 20px !important; }

.secret-reveal strong {
  color: var(--text);
  font-size: 1.3rem;
  letter-spacing: 0.3em;
}

.btn-share {
  width: 100%;
  padding: 14px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.1s;
  letter-spacing: 0.02em;
}

.btn-share:hover { opacity: 0.85; }

/* ===== ピッカー ===== */
.picker-content {
  text-align: left;
}

.picker-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-right: 32px;
}

#picker-digits {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.picker-digit-btn {
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.picker-digit-btn:hover  { background: var(--border); }
.picker-digit-btn:active { transform: scale(0.93); }

.picker-digit-btn.selected {
  border-color: var(--beer-color);
  background: rgba(245,166,35,0.2);
  color: var(--beer-color);
}

.picker-digit-btn.selected.confirmed-selected {
  border-color: var(--success);
  background: rgba(46,204,113,0.2);
  color: var(--success);
}

.picker-actions {
  display: flex;
  gap: 8px;
}

.picker-actions .btn {
  font-size: 0.85rem;
  padding: 10px;
}

/* ===== 遊び方モーダル ===== */
.howto-content {
  text-align: left;
  max-height: 82dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px !important;
}

.howto-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.howto-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--shirt-color), var(--beer-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.howto-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.howto-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.howto-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--shirt-color);
  margin-bottom: 10px;
}

.howto-section p {
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 8px;
}

.howto-section p:last-child { margin-bottom: 0; }

.howto-section strong { color: var(--text); }

.howto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  padding: 0;
}

.howto-list li {
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.5;
  padding-left: 4px;
}

.howto-list .s { color: var(--success);    font-weight: 700; }
.howto-list .b { color: var(--beer-color); font-weight: 700; }

.ex-answer {
  font-size: 0.78rem;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.ex-answer strong {
  color: var(--shirt-color);
  font-size: 1rem;
  letter-spacing: 0.15em;
}

.howto-example {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ex-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.ex-guess {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: 0.2em;
  min-width: 48px;
  white-space: nowrap;
}

.ex-result {
  min-width: 52px;
  font-weight: 700;
}

.ex-result .s { color: var(--success); }
.ex-result .b { color: var(--beer-color); }

.ex-desc {
  color: var(--text-sub);
  font-size: 0.78rem;
}

/* ===== フッター ===== */
.key-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 0 8px;
}

.key-footer-link {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 20px;
  background: rgba(74, 144, 217, 0.12);
  border: 1px solid rgba(74, 144, 217, 0.35);
  color: var(--shirt-color);
  font-size: 0.82rem;
  text-decoration: none;
  transition: background 0.2s;
}
.key-footer-link:hover { background: rgba(74, 144, 217, 0.24); }

/* 確定トグル ON */
.picker-toggle-on {
  border-color: var(--success) !important;
  color: var(--success) !important;
}

/* ===== 結果ポップアップ ===== */
.result-popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: pointer;
  animation: popup-fadein 0.18s ease;
}
.result-popup.hidden { display: none; }

@keyframes popup-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.popup-box {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--shirt-color);
  border-radius: 20px;
  padding: 32px 48px;
  text-align: center;
  min-width: 300px;
  animation: popup-bounce 0.28s ease;
}

.popup-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}

@keyframes popup-bounce {
  0%   { transform: scale(0.6); }
  65%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.popup-digits {
  font-size: 2.2rem;
  letter-spacing: 0.1em;
  white-space: nowrap;
  margin-bottom: 10px;
}

.popup-result {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 16px;
}
.popup-result .strike-num { font-size: 2.2rem; color: var(--success); }
.popup-result .ball-num   { font-size: 2.2rem; color: var(--beer-color); }
.popup-result .result-open { font-size: 2.2rem; color: var(--beer-color); }

.popup-hint {
  font-size: 0.9rem;
  color: var(--text-sub);
  font-style: italic;
  line-height: 1.6;
  white-space: pre-line;
}
