/* ============ コエ — 和紙と朱印 ============ */

:root {
  --paper: #f6f0e4;
  --paper-deep: #efe6d3;
  --ink: #26201a;
  --ink-soft: #6f6355;
  --ink-faint: #a2937f;
  --vermilion: #d8442e;
  --vermilion-deep: #b93521;
  --line: rgba(38, 32, 26, 0.14);
  --card: rgba(255, 253, 247, 0.72);
  --shadow: 0 10px 30px rgba(83, 62, 40, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #181310;
    --paper-deep: #211a15;
    --ink: #ede4d3;
    --ink-soft: #b0a390;
    --ink-faint: #7c705f;
    --vermilion: #e05237;
    --vermilion-deep: #c23f27;
    --line: rgba(237, 228, 211, 0.16);
    --card: rgba(33, 27, 21, 0.6);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- 紙の質感 --- */
.paper-grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.35 0 0 0 0 0.28 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.watermark {
  position: fixed;
  right: -0.12em;
  bottom: -0.22em;
  font-family: "Shippori Mincho", serif;
  font-weight: 800;
  font-size: clamp(280px, 60vw, 520px);
  line-height: 1;
  color: var(--ink);
  opacity: 0.045;
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

/* --- レイアウト --- */
.app {
  position: relative; z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 22px) 20px calc(env(safe-area-inset-bottom) + 32px);
  display: flex; flex-direction: column; gap: 20px;
}

/* --- ヘッダー --- */
.app-header {
  display: flex; align-items: center; gap: 14px;
  padding-top: 4px;
  animation: rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hanko {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  background: var(--vermilion);
  color: #fdf8ee;
  font-family: "Shippori Mincho", serif;
  font-weight: 800;
  font-size: 26px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(216, 68, 46, 0.35);
  transform: rotate(-3deg);
}

.app-title {
  font-family: "Shippori Mincho", serif;
  font-weight: 800;
  font-size: 28px;
  letter-spacing: 0.14em;
  line-height: 1.1;
}

.app-subtitle {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  margin-top: 2px;
}

/* --- 入力 --- */
.input-area {
  animation: rise 0.6s 0.06s cubic-bezier(0.22, 1, 0.36, 1) both;
}

textarea {
  width: 100%;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.9;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  resize: vertical;
  min-height: 180px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.25s, box-shadow 0.25s;
}

textarea::placeholder { color: var(--ink-faint); }

textarea:focus {
  outline: none;
  border-color: var(--vermilion);
  box-shadow: 0 0 0 3px rgba(216, 68, 46, 0.14), var(--shadow);
}

.input-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 6px 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.ghost-btn {
  font-family: inherit;
  font-size: 12px;
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.ghost-btn:active { color: var(--vermilion); border-color: var(--vermilion); }

/* --- 言語 --- */
.lang-area { animation: rise 0.6s 0.12s cubic-bezier(0.22, 1, 0.36, 1) both; }

.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-radius: 10px;
  padding: 9px 0;
  cursor: pointer;
  transition: background 0.25s, color 0.25s, box-shadow 0.25s;
}

.seg-btn.is-active {
  background: var(--vermilion);
  color: #fdf8ee;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(216, 68, 46, 0.3);
}

.detect-note {
  font-size: 12px;
  color: var(--ink-faint);
  padding: 8px 6px 0;
  min-height: 1.4em;
}

/* --- コントロール --- */
.control-area {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: rise 0.6s 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.control-row { display: flex; align-items: center; gap: 12px; }

.control-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  flex: 0 0 3em;
}

select {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  appearance: none;
  -webkit-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='%23a2937f' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--vermilion);
  border: 3px solid #fdf8ee;
  box-shadow: 0 2px 8px rgba(216, 68, 46, 0.4);
  cursor: pointer;
}

.rate-value {
  flex: 0 0 2.6em;
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--vermilion);
}

/* --- 高音質AI音声 --- */
.hq-details {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: rise 0.6s 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
  overflow: hidden;
}

.hq-summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: space-between;
}

.hq-summary::-webkit-details-marker { display: none; }
.hq-summary::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid var(--ink-faint);
  border-bottom: 2px solid var(--ink-faint);
  transform: rotate(45deg);
  transition: transform 0.25s;
}
.hq-details[open] .hq-summary::after { transform: rotate(-135deg); }

.hq-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #fdf8ee;
  background: var(--vermilion);
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 8px;
  vertical-align: 2px;
}

.hq-body {
  display: flex; flex-direction: column; gap: 12px;
  padding: 2px 18px 16px;
}

.hq-note {
  font-size: 12px;
  line-height: 1.9;
  color: var(--ink-soft);
}

.hq-note strong { color: var(--vermilion); }

.hq-row { display: flex; align-items: center; gap: 12px; }

.hq-row input[type="password"] {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

.hq-row input[type="password"]:focus { outline: none; border-color: var(--vermilion); }

.hq-toggle {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 0;
}

.hq-toggle input {
  width: 20px; height: 20px;
  accent-color: var(--vermilion);
}

.hq-status {
  font-size: 12px;
  color: var(--ink-faint);
  min-height: 1.2em;
  line-height: 1.7;
}

.hq-status.is-error { color: var(--vermilion); }

/* --- 再生 --- */
.play-area {
  display: flex; align-items: center; justify-content: center; gap: 22px;
  padding: 14px 0 6px;
  animation: rise 0.6s 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.play-btn {
  position: relative;
  display: grid; place-items: center;
  width: 92px; height: 92px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #e8604a, var(--vermilion) 58%, var(--vermilion-deep));
  color: #fdf8ee;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(216, 68, 46, 0.42), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.play-btn:active { transform: scale(0.94); }

.play-btn .icon-play { margin-left: 5px; }
.play-btn .icon-pause { display: none; }
.play-btn.is-speaking .icon-play { display: none; }
.play-btn.is-speaking .icon-pause { display: block; }

.ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(216, 68, 46, 0.5);
  opacity: 0;
  pointer-events: none;
}

.play-btn.is-speaking .ring { animation: pulse 2s ease-out infinite; }
.play-btn.is-speaking .ring-2 { animation-delay: 1s; }

.stop-btn {
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, opacity 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.stop-btn:disabled { opacity: 0.35; cursor: default; }
.stop-btn:not(:disabled):active { color: var(--vermilion); border-color: var(--vermilion); transform: scale(0.92); }

.play-hint {
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  min-width: 7em;
}

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

.save-btn { color: var(--vermilion); border-color: rgba(216, 68, 46, 0.4); font-weight: 700; }

/* --- フレーズ帳 --- */
.phrase-area {
  animation: rise 0.6s 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
  padding-top: 6px;
}

.phrase-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 0 2px 12px;
  flex-wrap: wrap;
}

.phrase-title {
  font-family: "Shippori Mincho", serif;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.12em;
  position: relative;
  padding-left: 14px;
}

.phrase-title::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%) rotate(-3deg);
  width: 6px; height: 1.1em;
  background: var(--vermilion);
  border-radius: 2px;
}

.phrase-controls { display: flex; align-items: center; gap: 8px; }

.repeat-label { font-size: 12px; color: var(--ink-soft); }

.repeat-select {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 26px 7px 10px;
  background-position: right 8px center;
}

.play-all-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #fdf8ee;
  background: var(--vermilion);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(216, 68, 46, 0.3);
  transition: transform 0.15s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.play-all-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
.play-all-btn:not(:disabled):active { transform: scale(0.95); }
.play-all-btn.is-playing { background: var(--ink-soft); box-shadow: none; }

.phrase-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 10px;
}

.phrase-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.phrase-card.is-playing {
  border-color: var(--vermilion);
  box-shadow: 0 0 0 3px rgba(216, 68, 46, 0.14), var(--shadow);
}

.card-play {
  flex: none;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--vermilion);
  color: #fdf8ee;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(216, 68, 46, 0.3);
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.card-play:active { transform: scale(0.92); }
.card-play .icon-play { margin-left: 2px; }
.card-play .icon-stop { display: none; }
.phrase-card.is-playing .card-play .icon-play { display: none; }
.phrase-card.is-playing .card-play .icon-stop { display: block; }

.card-body { flex: 1; min-width: 0; }

.card-text {
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-lang {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--vermilion);
  border: 1px solid rgba(216, 68, 46, 0.4);
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 5px;
}

.card-actions { flex: none; display: flex; flex-direction: column; gap: 2px; }

.card-actions button {
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  color: var(--ink-faint);
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.card-actions button:active { color: var(--vermilion); }

.phrase-empty {
  font-size: 13px;
  line-height: 2;
  color: var(--ink-faint);
  text-align: center;
  padding: 18px 0 6px;
}

.unsupported {
  font-size: 13px;
  color: var(--vermilion);
  text-align: center;
  line-height: 1.8;
}

/* --- アニメーション --- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0% { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.55); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
