/* ============================================
   おだてブタ2 期待値カウンター - Stylesheet
   ============================================ */

/* --- Reset & Variables --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #232342;
  --bg-elevated: #2d2d50;
  --text-primary: #e8e8ec;
  --text-secondary: #7a7a9e;
  --text-muted: #55556e;
  --accent-naki: #4a9eff;
  --accent-hiroi: #ff6b6b;
  --accent-atari: #ffd93d;
  --accent-record: #34d399;
  --accent-positive: #4ade80;
  --accent-negative: #f87171;
  --danger: #ef4444;
  --warn: #f59e0b;
  --border: #2e2e4a;
  --nav-height: 56px;
  --header-height: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  position: relative;
}

/* --- Header --- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.app-header .subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}

/* --- Pages --- */
.page {
  position: absolute;
  top: calc(var(--header-height) + var(--safe-top));
  left: 0; right: 0;
  bottom: calc(var(--nav-height) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: none;
  flex-direction: column;
}

.page.active {
  display: flex;
}

/* --- Bottom Navigation --- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary);
  display: flex;
  border-top: 1px solid var(--border);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active {
  color: var(--accent-naki);
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-label {
  font-weight: 600;
}

/* =====================
   COUNTER PAGE
   ===================== */

.session-info {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
}

/* Live Border / Stats Display */
.live-border {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.lb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  flex-wrap: wrap;
}

.lb-target {
  color: var(--accent-atari);
  font-weight: 600;
}

.lb-sep {
  color: var(--text-muted);
}

.lb-ok {
  color: var(--accent-positive);
}

.lb-ng {
  color: var(--accent-negative);
}

/* Counter Display */
.counter-display {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 20px;
  padding: 10px 0 14px;
}

.counter-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  max-width: 150px;
}

.counter-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.counter-group:nth-child(1) .counter-label { color: var(--accent-naki); }
.counter-group:nth-child(2) .counter-label { color: var(--accent-hiroi); }

.counter-value {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  padding: 10px 20px;
  border-radius: 14px;
  background: var(--bg-card);
  cursor: pointer;
  transition: background 0.15s;
  min-width: 100px;
  text-align: center;
  border: 2px solid transparent;
}

.counter-value:active {
  background: var(--bg-elevated);
}

.counter-group:nth-child(1) .counter-value { border-color: var(--accent-naki); color: var(--accent-naki); }
.counter-group:nth-child(2) .counter-value { border-color: var(--accent-hiroi); color: var(--accent-hiroi); }

/* Counter Buttons */
.counter-buttons {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
  min-height: 0;
}

.btn-row-main {
  display: flex;
  gap: 10px;
  flex: 1;
  min-height: 90px;
}

.btn-row-sub {
  display: flex;
  gap: 10px;
}

/* General Button Styles */
.btn {
  border: none;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.08s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: inherit;
}

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

/* Main Count Buttons */
.btn-count {
  flex: 1;
  font-size: 20px;
  line-height: 1.3;
  color: #fff;
}

.btn-naki {
  background: var(--accent-naki);
}

.btn-hiroi {
  background: var(--accent-hiroi);
}

.btn-plus {
  font-size: 32px;
  font-weight: 900;
}

/* Minus Buttons */
.btn-minus {
  flex: 1;
  height: 38px;
  font-size: 16px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Counter Actions */
.counter-actions {
  display: flex;
  gap: 8px;
  padding-top: 10px;
}

.btn-record {
  flex: 1;
  height: 54px;
  font-size: 18px;
  background: var(--accent-record);
  color: #0f0f1a;
}

.btn-undo {
  width: 80px;
  height: 54px;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--warn);
  border: 1px solid var(--warn);
}

/* Record flash animation */
@keyframes flash-green {
  0% { background-color: var(--accent-record); }
  100% { background-color: var(--bg-primary); }
}

.flash-success {
  animation: flash-green 0.5s ease-out;
}

/* =====================
   HISTORY PAGE
   ===================== */

.history-header {
  flex-shrink: 0;
}

.history-session-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.session-select {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7a9e' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.btn-new-session {
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
  background: var(--accent-naki);
  color: #fff;
  white-space: nowrap;
}

.history-summary {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  display: none;
}

.history-summary.has-data {
  display: block;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
}

.summary-row span:first-child {
  color: var(--text-secondary);
}

.summary-row span:last-child {
  font-weight: 700;
}

.summary-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* Session Results */
.session-results {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.session-results h3 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.sr-inputs {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.sr-field {
  flex: 1;
}

.sr-field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.sr-field input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  -webkit-user-select: text;
  user-select: text;
}

.sr-field input:focus {
  outline: none;
  border-color: var(--accent-naki);
}

.sr-calc {
  font-size: 13px;
  line-height: 1.8;
}

.sr-calc-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.sr-calc-row span:first-child {
  color: var(--text-secondary);
}

.sr-calc-row.sr-positive span:last-child {
  color: var(--accent-positive);
  font-weight: 800;
}

.sr-calc-row.sr-negative span:last-child {
  color: var(--accent-negative);
  font-weight: 800;
}

.sr-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* History List */
.history-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-item {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  gap: 10px;
}

.history-num {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  min-width: 28px;
}

.history-data {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.history-stat {
  font-size: 13px;
}

.history-stat .hs-label {
  color: var(--text-secondary);
  font-size: 11px;
}

.history-stat .hs-val {
  font-weight: 700;
  margin-left: 2px;
}

.hs-naki { color: var(--accent-naki); }
.hs-hiroi { color: var(--accent-hiroi); }

.history-time {
  font-size: 10px;
  color: var(--text-muted);
}

.history-del {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.history-del:active {
  color: var(--danger);
  border-color: var(--danger);
}

.history-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}

.history-empty p {
  font-size: 16px;
}

.history-empty .hint {
  font-size: 12px;
  line-height: 1.6;
}

/* =====================
   ANALYSIS PAGE
   ===================== */

.analysis-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.analysis-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-row {
  display: flex;
  gap: 8px;
}

.stat-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.stat-label {
  font-size: 10px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
}

/* Analysis Inputs */
.analysis-inputs {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.analysis-inputs h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.input-group {
  margin-bottom: 12px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.input-group input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  -webkit-user-select: text;
  user-select: text;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent-naki);
}

.input-with-prefix {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-prefix {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.input-with-prefix input {
  flex: 1;
}

.input-hint {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Analysis Results */
.analysis-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
}

.result-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-main {
  border: 2px solid var(--border);
}

.result-main.positive {
  border-color: var(--accent-positive);
}

.result-main.negative {
  border-color: var(--accent-negative);
}

.result-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.result-value {
  font-size: 28px;
  font-weight: 900;
}

.result-main .result-value {
  font-size: 36px;
}

.result-main.positive .result-value {
  color: var(--accent-positive);
}

.result-main.negative .result-value {
  color: var(--accent-negative);
}

.result-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0;
  line-height: 1.6;
  white-space: pre-line;
}

/* =====================
   SETTINGS PAGE
   ===================== */

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.settings-info {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 4px 14px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row span:first-child {
  color: var(--text-secondary);
}

.btn-warn {
  width: 100%;
  height: 44px;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--warn);
  border: 1px solid var(--warn);
  margin-bottom: 8px;
}

.btn-danger {
  width: 100%;
  height: 44px;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.settings-note {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 10px;
}

.btn-install {
  width: 100%;
  height: 44px;
  font-size: 14px;
  background: var(--accent-naki);
  color: #fff;
}

.app-version {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 20px;
}

/* =====================
   MODALS
   ===================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  border: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  margin-bottom: 16px;
  text-align: center;
}

.modal-message {
  font-size: 14px;
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
  white-space: pre-line;
}

.modal-input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--accent-naki);
  border-radius: 10px;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  font-family: inherit;
  -webkit-user-select: text;
  user-select: text;
}

.modal-input:focus {
  outline: none;
}

.modal-buttons {
  display: flex;
  gap: 10px;
}

.btn-cancel {
  flex: 1;
  height: 44px;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-confirm {
  flex: 1;
  height: 44px;
  font-size: 14px;
  background: var(--accent-naki);
  color: #fff;
}

.modal-buttons .btn-danger {
  flex: 1;
  margin-bottom: 0;
}

/* =====================
   UTILITY
   ===================== */

::-webkit-scrollbar {
  width: 3px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

.analysis-nodata {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 14px;
  line-height: 1.8;
}
