/* =========================================
   Speech Timer — style.css
   モバイルファースト設計
   ========================================= */

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

:root {
  --color-primary: #1a56db;
  --color-primary-dark: #1341ae;
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-sub: #6b7280;
  --color-header-bg: #1e3a5f;

  /* タイマー状態色 */
  --color-green: #16a34a;
  --color-yellow: #d97706;
  --color-red: #dc2626;
  --color-green-bg: #f0fdf4;
  --color-yellow-bg: #fffbeb;
  --color-red-bg: #fef2f2;

  --radius: 10px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

/* =========================================
   Header
   ========================================= */
header {
  background: var(--color-header-bg);
  color: #fff;
  padding: 1.25rem 1rem;
  text-align: center;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.8;
  margin-top: 0.375rem;
}

/* =========================================
   Main / Layout
   ========================================= */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* =========================================
   Ad Unit
   ========================================= */
.ad-unit {
  margin: 1.25rem 0;
}

/* =========================================
   Panel (共通カード)
   ========================================= */
.panel {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.panel h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-header-bg);
  margin-bottom: 0.75rem;
}

.panel-hint {
  font-size: 0.8rem;
  color: var(--color-text-sub);
  margin-bottom: 0.75rem;
}

/* =========================================
   Tool Section wrapper
   ========================================= */
.tool-section {
  margin-bottom: 1rem;
}

/* =========================================
   Script Panel — テキストエリア
   ========================================= */
#script-input {
  width: 100%;
  min-height: 160px;
  padding: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.6;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  resize: vertical;
  font-family: inherit;
  color: var(--color-text);
  background: #fafafa;
  transition: border-color 0.15s;
}

#script-input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

.script-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--color-text-sub);
  align-items: center;
}

.script-stats .sep {
  color: var(--color-border);
}

#char-count {
  font-weight: 700;
  color: var(--color-text);
}

/* =========================================
   Timer Setup Panel — プリセット・時間入力
   ========================================= */
.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}

.preset-btn {
  flex: 1 1 auto;
  min-width: 52px;
  min-height: 44px;
  padding: 0.5rem 0.625rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 2px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.preset-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.preset-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.time-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.time-input-row label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-sub);
  white-space: nowrap;
}

.time-input-row input[type="number"] {
  width: 72px;
  min-height: 44px;
  padding: 0.5rem 0.625rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  background: #fafafa;
}

.time-input-row input[type="number"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

.time-sep {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-sub);
}

/* =========================================
   Timer Panel — カウントダウン表示
   ========================================= */
.timer-panel {
  text-align: center;
}

.timer-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 6px solid var(--color-green);
  background: var(--color-green-bg);
  margin: 0.5rem auto 1rem;
  transition: border-color 0.3s, background 0.3s;
}

#timer-text {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--color-green);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

/* タイマー状態: 黄 */
.timer-display.warn {
  border-color: var(--color-yellow);
  background: var(--color-yellow-bg);
}
.timer-display.warn #timer-text {
  color: var(--color-yellow);
}

/* タイマー状態: 赤 */
.timer-display.danger {
  border-color: var(--color-red);
  background: var(--color-red-bg);
}
.timer-display.danger #timer-text {
  color: var(--color-red);
}

/* タイマー状態: 時間切れ */
.timer-display.overtime {
  border-color: var(--color-red);
  background: var(--color-red-bg);
  animation: pulse 1s ease-in-out infinite;
}
.timer-display.overtime #timer-text {
  color: var(--color-red);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* =========================================
   Progress Bar
   ========================================= */
.progress-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.875rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--color-green);
  border-radius: 999px;
  transition: width 0.5s linear, background 0.3s;
}

.progress-bar.warn {
  background: var(--color-yellow);
}

.progress-bar.danger {
  background: var(--color-red);
}

/* =========================================
   Pace Display
   ========================================= */
.pace-display {
  font-size: 0.875rem;
  color: var(--color-text-sub);
  margin-bottom: 1rem;
}

#pace-value {
  font-weight: 700;
  color: var(--color-text);
  margin-left: 0.25rem;
}

.pace-note {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-sub);
  margin-top: 0.125rem;
}

/* =========================================
   Timer Controls
   ========================================= */
.timer-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary {
  min-height: 56px;
  padding: 0 2rem;
  font-size: 1.0625rem;
  font-weight: 700;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  flex: 1 1 120px;
  max-width: 200px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

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

.btn-secondary {
  min-height: 44px;
  padding: 0 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  flex: 1 1 90px;
  max-width: 160px;
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

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

/* =========================================
   Sections Panel
   ========================================= */
.section-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--color-border);
  gap: 1rem;
}

.section-item:last-child {
  border-bottom: none;
}

.section-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  flex: 1;
}

.section-chars {
  font-size: 0.8rem;
  color: var(--color-text-sub);
}

.section-time {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}

.empty-sections {
  font-size: 0.875rem;
  color: var(--color-text-sub);
}

/* =========================================
   History Panel
   ========================================= */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
  gap: 0.5rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  color: var(--color-text-sub);
  font-size: 0.8rem;
  white-space: nowrap;
}

.history-result {
  font-weight: 700;
}

.history-result.over {
  color: var(--color-red);
}

.history-result.ok {
  color: var(--color-green);
}

.empty-msg {
  font-size: 0.875rem;
  color: var(--color-text-sub);
}

.btn-text {
  background: none;
  border: none;
  color: var(--color-text-sub);
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
  text-decoration: underline;
  min-height: 44px;
}

.btn-text:hover {
  color: var(--color-red);
}

/* =========================================
   Howto Section
   ========================================= */
.howto-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}

.howto-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-header-bg);
  margin-top: 1.25rem;
  margin-bottom: 0.625rem;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: #374151;
}

.howto-section li {
  margin-bottom: 0.5rem;
}

.howto-section p {
  font-size: 0.9rem;
  color: #374151;
  margin-bottom: 0.75rem;
  line-height: 1.75;
}

/* =========================================
   Footer
   ========================================= */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8125rem;
  color: var(--color-text-sub);
}

footer a {
  color: #555;
  text-decoration: underline;
}

footer a:hover {
  color: var(--color-primary);
}

/* =========================================
   Responsive — 640px以上
   ========================================= */
@media (min-width: 640px) {
  header h1 {
    font-size: 1.625rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .panel {
    padding: 1.5rem;
  }

  #script-input {
    min-height: 200px;
  }

  .timer-display {
    width: 200px;
    height: 200px;
  }

  #timer-text {
    font-size: 3.25rem;
  }

  .pace-note {
    display: inline;
    margin-top: 0;
    margin-left: 0.5rem;
  }

  .timer-controls {
    flex-wrap: nowrap;
  }
}
