:root {
  --bg: #fbf7f6;
  --panel: #ffffff;
  --panel-soft: #fff4f1;
  --text: #3f3944;
  --muted: #817785;
  --primary: #e884a1;
  --primary-dark: #cf6588;
  --success: #68b7a8;
  --success-dark: #4b9b91;
  --line: #eadfe3;
  --gauge: #f5a7b7;
  --shadow: 0 18px 50px rgba(103, 78, 91, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 213, 221, 0.48), transparent 28%),
    radial-gradient(circle at 90% 12%, rgba(187, 225, 218, 0.45), transparent 25%),
    linear-gradient(145deg, #fffaf9 0%, #f7fbfa 100%);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: center;
}

.companion-panel,
.side-panel {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(234, 223, 227, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.companion-panel {
  min-height: 680px;
  padding: 28px;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.side-panel {
  max-height: calc(100vh - 56px);
  overflow: auto;
  border-radius: 22px;
  padding: 20px;
}

.title-area {
  align-self: stretch;
  text-align: center;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(1.8rem, 5vw, 3rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.speech-wrap {
  width: min(560px, 100%);
  min-height: 92px;
  display: grid;
  place-items: end center;
}

.speech-bubble {
  position: relative;
  width: 100%;
  min-height: 72px;
  padding: 18px 22px;
  border: 2px solid #f0cad3;
  border-radius: 22px;
  background: #fff;
  color: #4a3d48;
  font-size: clamp(1rem, 3.2vw, 1.18rem);
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
  box-shadow: 0 12px 30px rgba(192, 120, 145, 0.12);
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -13px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-right: 2px solid #f0cad3;
  border-bottom: 2px solid #f0cad3;
  transform: translateX(-50%) rotate(45deg);
}

.character {
  position: relative;
  --character-zoom: 1.72;
  width: min(540px, 88vw);
  aspect-ratio: 1;
  margin: -8px 0 -18px;
  transform-origin: 50% 100%;
  animation: companionBreathe 5.8s ease-in-out infinite;
}

.character::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: 17%;
  height: 34px;
  border-radius: 50%;
  background: rgba(89, 71, 88, 0.16);
  filter: blur(5px);
  z-index: 0;
}

.character-image,
.character-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.character-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 22px 28px rgba(95, 75, 91, 0.14));
  transform: scale(var(--character-zoom));
  transform-origin: 50% 62%;
  transition: transform 0.35s ease, filter 0.35s ease, opacity 0.22s ease;
  animation: subtleMouth 4.6s ease-in-out infinite;
  pointer-events: none;
}

.character:hover .character-image {
  transform: translateY(-5px) scale(calc(var(--character-zoom) * 1.015)) rotate(0.6deg);
}

.character.is-starting .character-image {
  animation: startPop 0.72s ease both, subtleMouth 4.6s ease-in-out infinite 0.72s;
}

.character.is-completing .character-image {
  animation: completeBounce 0.9s ease both, subtleMouth 4.6s ease-in-out infinite 0.9s;
}

.character.is-speaking .character-image {
  animation: speakingPulse 0.7s ease both, subtleMouth 4.6s ease-in-out infinite 0.7s;
}

.character-placeholder {
  display: grid;
  place-content: center;
  gap: 8px;
  border: 2px dashed #efcad4;
  border-radius: 28px;
  background: linear-gradient(145deg, #fff8f6, #f2fbf8);
  color: var(--muted);
  text-align: center;
}

.character-placeholder[hidden] {
  display: none;
}

.character-placeholder span {
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 1.1rem;
}

.particle-layer {
  position: absolute;
  inset: 7% 9%;
  z-index: 2;
  pointer-events: none;
}

.particle-layer span {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 218, 143, 0.95);
  opacity: 0;
  box-shadow: 0 0 16px rgba(255, 211, 125, 0.8);
}

.particle-layer span:nth-child(1) {
  left: 18%;
  top: 35%;
}

.particle-layer span:nth-child(2) {
  left: 74%;
  top: 26%;
}

.particle-layer span:nth-child(3) {
  left: 28%;
  top: 66%;
}

.particle-layer span:nth-child(4) {
  left: 82%;
  top: 57%;
}

.particle-layer span:nth-child(5) {
  left: 50%;
  top: 18%;
}

.character.show-sparkles .particle-layer span {
  animation: particleRise 1.3s ease-out both;
}

.character.show-sparkles .particle-layer span:nth-child(2) {
  animation-delay: 0.1s;
}

.character.show-sparkles .particle-layer span:nth-child(3) {
  animation-delay: 0.18s;
}

.character.show-sparkles .particle-layer span:nth-child(4) {
  animation-delay: 0.26s;
}

.character.show-sparkles .particle-layer span:nth-child(5) {
  animation-delay: 0.34s;
}

.task-setup {
  width: min(520px, 100%);
  margin: 0 0 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.76);
}

.task-setup label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.task-setup textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  line-height: 1.6;
}

.task-setup[hidden] {
  display: none;
}

.timer-stage {
  width: min(520px, 100%);
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  text-align: center;
  box-shadow: 0 14px 32px rgba(103, 78, 91, 0.08);
}

.mode-badge {
  display: inline-flex;
  min-height: 30px;
  padding: 5px 14px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--primary-dark);
  background: #fff;
  font-size: 0.88rem;
  font-weight: 800;
}

.current-task {
  max-width: 100%;
  margin: 12px auto 0;
  padding: 10px 14px;
  border-radius: 14px;
  color: #5a4d58;
  background: rgba(255, 255, 255, 0.72);
  font-size: clamp(0.94rem, 2.6vw, 1.08rem);
  font-weight: 800;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.current-task.is-empty {
  color: var(--muted);
}

.time-display {
  margin: 8px 0 12px;
  font-variant-numeric: tabular-nums;
  font-size: clamp(4rem, 14vw, 7.4rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: #efe6e8;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f4a6b8, #8acfc5);
  transition: width 0.25s linear;
}

.actions {
  width: min(520px, 100%);
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 12px;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
  color: #fff;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.primary-btn {
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(232, 132, 161, 0.3);
}

.success-btn {
  background: var(--success);
  box-shadow: 0 10px 22px rgba(104, 183, 168, 0.28);
}

.secondary-btn {
  color: #fff;
  background: #8fb7d4;
  box-shadow: 0 10px 22px rgba(107, 151, 184, 0.22);
}

.ghost-btn {
  width: 100%;
  margin-top: 18px;
  color: var(--primary-dark);
  border: 1px solid #f0cad3;
  background: #fff;
}

.ghost-btn.compact {
  margin-top: 0;
}

.danger-btn {
  width: 100%;
  margin-top: 12px;
  color: #bd5a67;
  border: 1px solid #efc3ca;
  background: #fff;
}

.danger-btn.compact {
  margin-top: 0;
  grid-column: 1 / -1;
}

.status-section,
.settings-section,
.music-section,
.ad-section,
.history-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.history-section {
  border-bottom: 0;
}

.affection-row,
.range-row,
.section-heading,
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.affection-row strong {
  color: var(--primary-dark);
  font-size: 1.35rem;
}

.gauge {
  height: 14px;
  margin: 10px 0 8px;
  border-radius: 999px;
  background: #f0e8ea;
  overflow: hidden;
}

.gauge-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f7b2bd, #87cfc3);
  transition: width 0.4s ease;
}

.affection-label {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats-grid div {
  padding: 12px;
  border-radius: 14px;
  background: #fbf6f5;
}

.stats-grid span,
.range-hints,
.history-list time {
  color: var(--muted);
  font-size: 0.78rem;
}

.stats-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1.15rem;
}

.toggle-row {
  justify-content: flex-start;
  margin-bottom: 16px;
  font-weight: 700;
}

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

.range-row strong {
  color: var(--success-dark);
  font-size: 0.9rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--success);
}

.range-hints {
  display: flex;
  justify-content: space-between;
}

.music-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

.music-description,
.music-message {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

.music-now {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 12px;
  color: #5a4d58;
  background: #fbf6f5;
  font-size: 0.88rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.music-message {
  min-height: 1.3em;
  color: #bd5a67;
}

.music-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 14px;
}

.music-actions .ghost-btn {
  margin-top: 0;
}

.adsense-container {
  width: 100%;
  text-align: center;
}

.ad-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
}

.adsense-placeholder {
  display: block;
  width: 100%;
  min-height: 250px;
  border: 1px dashed #e9cbd3;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
}

.adsense-slot {
  max-width: 100%;
  border: 0;
  background: transparent;
}

.adsense-placeholder {
  display: grid;
  place-items: center;
  padding: 16px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.number-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.setup-duration-grid {
  margin: 12px 0 0;
}

.number-grid label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: #fbf6f5;
}

.number-grid label span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.78rem;
}

.number-grid input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  color: var(--text);
  background: #fff;
  font-weight: 800;
}

.number-grid small {
  align-self: center;
  color: var(--muted);
}

.history-list {
  max-height: 220px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.history-list li:last-child {
  border-bottom: 0;
}

.history-list strong {
  display: block;
  font-size: 0.92rem;
}

.empty-history {
  color: var(--muted);
  font-size: 0.9rem;
}

@keyframes companionBreathe {
  0%,
  100% {
    transform: translateY(0) rotate(-0.4deg);
  }
  50% {
    transform: translateY(-7px) rotate(0.4deg);
  }
}

@keyframes subtleMouth {
  0%,
  100% {
    transform: scale(var(--character-zoom));
    filter: drop-shadow(0 22px 28px rgba(95, 75, 91, 0.14));
  }
  50% {
    transform: scale(calc(var(--character-zoom) * 1.006));
    filter: drop-shadow(0 24px 30px rgba(95, 75, 91, 0.16));
  }
}

@keyframes speakingPulse {
  0%,
  100% {
    transform: scale(var(--character-zoom));
  }
  35% {
    transform: scale(calc(var(--character-zoom) * 1.018)) translateY(-2px);
  }
  70% {
    transform: scale(calc(var(--character-zoom) * 1.006));
  }
}

@keyframes startPop {
  0% {
    transform: translateY(0) scale(var(--character-zoom));
  }
  45% {
    transform: translateY(-14px) scale(calc(var(--character-zoom) * 1.035));
  }
  100% {
    transform: translateY(0) scale(var(--character-zoom));
  }
}

@keyframes completeBounce {
  0% {
    transform: translateY(0) scale(var(--character-zoom));
  }
  34% {
    transform: translateY(-20px) scale(calc(var(--character-zoom) * 1.045));
  }
  62% {
    transform: translateY(4px) scale(calc(var(--character-zoom) * 0.99));
  }
  100% {
    transform: translateY(0) scale(var(--character-zoom));
  }
}

@keyframes particleRise {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.5);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-44px) scale(1.08);
  }
}

@media (max-width: 860px) {
  .app-shell {
    min-height: auto;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .companion-panel {
    min-height: 0;
    padding: 22px 16px;
  }

  .character {
    --character-zoom: 1.62;
    width: min(500px, 92vw);
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: min(100% - 18px, 1120px);
    padding: 10px 0;
    gap: 10px;
  }

  .companion-panel,
  .side-panel {
    border-radius: 18px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .speech-bubble {
    padding: 15px 16px;
  }

  .character {
    --character-zoom: 1.52;
    width: min(420px, 94vw);
  }

  .number-grid {
    grid-template-columns: 1fr;
  }
}
