:root {
  color-scheme: light dark;
  --bg-light: #f3f4f6;
  --bg-dark: #1f2933;
  --text-light: #1f2933;
  --text-dark: #e5e7eb;
  --accent: #3b82f6;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --muted: #6b7280;
  --card-light: #ffffff;
  --card-dark: #2d3748;
  font-family: 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0b3b2e 0%, #14532d 60%, #1f2933 100%);
  color: var(--text-light);
  font-family: var(--font-family);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body.dark {
  color: var(--text-dark);
}

body {
  -webkit-tap-highlight-color: transparent;
}

#root {
  min-height: 100vh;
}

.tree-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
}

.tree-trunk {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(300px, 40vw, 520px);
  max-width: 520px;
  background: linear-gradient(180deg, #5c3a21 0%, #4a2f19 100%);
  border-bottom-left-radius: 36px;
  border-bottom-right-radius: 36px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  transition: height 0.3s ease;
  z-index: 1;
}

.tree-content {
  position: relative;
  width: min(900px, 100%);
  padding: 80px 24px 120px;
  z-index: 2;
}

.tree-header {
  text-align: center;
  color: #f5f3ff;
  position: sticky;
  top: 40px;
  background: rgba(15, 23, 42, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding-bottom: 24px;
  margin-bottom: 24px;
}

.tree-header h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0;
  font-weight: 700;
}

.tree-header p {
  margin: 8px 0 0;
  font-size: 1rem;
  opacity: 0.8;
}

.tree-hole {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tree-hole button {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px solid rgba(249, 200, 54, 0.7);
  background: rgba(249, 200, 54, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.tree-hole button.locked {
  border-color: rgba(148, 163, 184, 0.7);
  background: rgba(30, 41, 59, 0.6);
  color: rgba(226, 232, 240, 0.85);
}

.tree-hole button:hover {
  transform: translateY(-6px) scale(1.05);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45);
}

.hole-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tree-hole .hole-date {
  font-size: 0.7rem;
  color: rgba(248, 250, 252, 0.8);
  background: rgba(30, 41, 59, 0.55);
  padding: 2px 8px;
  border-radius: 9999px;
  white-space: nowrap;
}

.tree-hole .hole-name {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.55);
  color: #f8fafc;
  white-space: nowrap;
}

.chat-container,
.history-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-light);
}

.dark .chat-container,
.dark .history-container {
  background: #111827;
  color: var(--text-dark);
}

.chat-header,
.history-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  background: var(--card-light);
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
}

.dark .chat-header,
.dark .history-header {
  background: var(--card-dark);
  border-bottom-color: #374151;
}

.icon-button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 12px;
  transition: background 0.2s ease, color 0.2s ease;
}

.icon-button:hover {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
}

.hole-name-input {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  border: none;
  background: transparent;
  font-weight: 600;
  color: inherit;
  outline: none;
  border-radius: 8px;
  padding: 6px 8px;
}

.hole-name-input:focus {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.96) 0%, rgba(226, 232, 240, 0.85) 100%);
}

.dark .chat-body {
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.95) 0%, rgba(30, 41, 59, 0.75) 100%);
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: min(75%, 420px);
}

.chat-message.from-user {
  align-self: flex-end;
  text-align: right;
}

.chat-message.from-ai {
  align-self: flex-start;
  text-align: left;
}

.message-bubble {
  padding: 14px 16px;
  border-radius: 18px;
  background: #ffffff;
  color: #1f2937;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  font-size: 0.95rem;
  line-height: 1.5;
  animation: fade-in 0.25s ease-out both;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.dark .message-bubble {
  background: #1f2937;
  color: #e5e7eb;
}

.chat-message.from-user .message-bubble {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #f8fafc;
  border-bottom-right-radius: 4px;
}

.chat-message.from-ai .message-bubble {
  border-bottom-left-radius: 4px;
}

.message-image {
  max-width: min(260px, 80vw);
  max-height: 240px;
  border-radius: 12px;
  display: block;
}

.message-time {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

.typing-indicator {
  display: inline-flex;
  gap: 6px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: pulse 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

.chat-footer {
  position: sticky;
  bottom: 0;
  background: var(--card-light);
  border-top: 1px solid #e5e7eb;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.05);
}

.dark .chat-footer {
  background: var(--card-dark);
  border-top-color: #374151;
}

.storage-indicator {
  padding: 14px 20px;
  cursor: pointer;
}

.storage-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.storage-bar {
  width: 100%;
  height: 10px;
  border-radius: 9999px;
  background: #e5e7eb;
  overflow: hidden;
}

.storage-progress {
  height: 100%;
  border-radius: inherit;
  transition: width 0.3s ease;
}

.input-area {
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.image-preview {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.2);
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-preview {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(220, 38, 38, 0.3);
}

.compose-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.textarea {
  flex: 1;
  min-height: 46px;
  max-height: 160px;
  padding: 12px 14px;
  border-radius: 9999px;
  border: 1px solid #cbd5f5;
  resize: none;
  font-size: 0.95rem;
  background: #f1f5f9;
  color: var(--text-light);
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.textarea::placeholder {
  color: rgba(100, 116, 139, 0.8);
}

.dark .textarea {
  background: #111827;
  border-color: #374151;
  color: var(--text-dark);
}

.dark .textarea::placeholder {
  color: rgba(148, 163, 184, 0.8);
}

.upload-button,
.send-button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.upload-button {
  background: #e2e8f0;
  color: #475569;
}

.upload-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.18);
}

.send-button {
  background: var(--accent);
  color: white;
}

.send-button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 24px rgba(59, 130, 246, 0.3);
}

.send-button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.history-controls {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: rgba(248, 250, 252, 0.95);
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 72px;
  z-index: 4;
}

.dark .history-controls {
  background: rgba(17, 24, 39, 0.92);
  border-bottom-color: #374151;
}

.history-controls input,
.history-controls select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #cbd5f5;
  background: #ffffff;
  font-size: 0.95rem;
}

.dark .history-controls input,
.dark .history-controls select {
  background: #111827;
  color: var(--text-dark);
  border-color: #374151;
}

.history-list {
  padding: 20px 24px 120px;
  flex: 1 0 auto;
  overflow: visible;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 100px 0;
}

.history-item {
  background: var(--card-light);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  gap: 16px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.dark .history-item {
  background: var(--card-dark);
}

.history-item img {
  max-width: min(220px, 70vw);
  border-radius: 12px;
}

.history-item p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
}

.history-item .meta {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.selection-bar {
  position: sticky;
  bottom: 0;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-top: 1px solid #e5e7eb;
  animation: fade-in-up 0.2s ease-out both;
}

.dark .selection-bar {
  background: rgba(17, 24, 39, 0.9);
  border-top-color: #374151;
}

@supports not ((backdrop-filter: blur(1px))) {
  .tree-header {
    background: rgba(15, 23, 42, 0.85);
  }

  .selection-bar {
    background: rgba(255, 255, 255, 0.98);
  }

  .dark .selection-bar {
    background: rgba(17, 24, 39, 0.95);
  }
}

.delete-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--danger);
  color: white;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 12px 24px rgba(220, 38, 38, 0.28);
}

@media (max-width: 768px) {
  .tree-content {
    padding: 72px 16px 96px;
  }

  .tree-trunk {
    width: clamp(240px, 70vw, 460px);
  }

  .chat-header,
  .history-header {
    padding: 14px 16px;
  }

  .storage-indicator {
    padding: 10px 16px;
  }

  .input-area {
    padding: 12px 16px 18px;
  }

  .compose-row {
    align-items: center;
    gap: 10px;
  }

  .textarea {
    border-radius: 20px;
    background: rgba(241, 245, 249, 0.95);
  }

  .upload-button,
  .send-button {
    width: 42px;
    height: 42px;
  }
}

.delete-button svg {
  width: 18px;
  height: 18px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.25s ease-out both;
}

.modal-card {
  background: var(--card-light);
  color: inherit;
  padding: 28px;
  border-radius: 20px;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.25);
  max-width: min(480px, 90vw);
  width: 100%;
  position: relative;
  animation: fade-in-up 0.3s ease-out both;
}

.dark .modal-card {
  background: var(--card-dark);
}

.modal-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.modal-subtitle {
  margin: 6px 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.keypad button {
  padding: 14px 0;
  border-radius: 16px;
  border: none;
  font-size: 1.3rem;
  background: #e2e8f0;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.keypad button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.15);
}

.modal-danger-link {
  margin-top: 16px;
  display: inline-flex;
  justify-content: center;
  width: 100%;
  font-size: 0.85rem;
  color: var(--danger);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

.modal-danger-link:hover {
  color: #b91c1c;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 18px 0;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #cbd5f5;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.error-text {
  color: var(--danger);
  text-align: center;
  min-height: 18px;
  font-size: 0.9rem;
}

.modal-actions {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions button {
  padding: 12px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.modal-actions .secondary {
  background: #e2e8f0;
  color: #1f2937;
}

.modal-actions .primary {
  background: var(--accent);
  color: white;
}

.cloud-modal-card {
  max-width: min(540px, 92vw);
  padding: 32px;
}

.cloud-close {
  position: absolute;
  top: 18px;
  right: 18px;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
}

.cloud-close:hover {
  color: var(--accent);
}

.cloud-section {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cloud-section h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.cloud-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cloud-field span {
  font-size: 0.9rem;
  color: var(--muted);
}

.cloud-field input {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  font-size: 0.95rem;
  background: var(--card-light);
  color: inherit;
}

.cloud-field input:disabled {
  opacity: 0.65;
}

.dark .cloud-field input {
  background: var(--card-dark);
  border-color: #374151;
}

.cloud-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.cloud-hint code {
  background: rgba(148, 163, 184, 0.18);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.82rem;
}

.cloud-auth-tabs {
  display: inline-flex;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
  align-self: flex-start;
}

.cloud-auth-tabs button {
  border: none;
  background: transparent;
  padding: 8px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
}

.cloud-auth-tabs button.active {
  background: var(--accent);
  color: white;
}

.cloud-button {
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.cloud-button.primary {
  background: var(--accent);
  color: #fff;
}

.cloud-button.secondary {
  background: #e2e8f0;
  color: #1f2937;
}

.cloud-button.danger {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
}

.cloud-button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.cloud-button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16);
}

.cloud-banner {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin: 10px 0 0;
}

.cloud-banner.success {
  background: rgba(34, 197, 94, 0.16);
  color: #166534;
}

.cloud-banner.info {
  background: rgba(59, 130, 246, 0.18);
  color: #1d4ed8;
}

.cloud-banner.error {
  background: rgba(239, 68, 68, 0.18);
  color: #b91c1c;
}

.dark .cloud-banner.success {
  color: #86efac;
  background: rgba(34, 197, 94, 0.25);
}

.dark .cloud-banner.info {
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.28);
}

.dark .cloud-banner.error {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.26);
}

.cloud-summary {
  background: rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.dark .cloud-summary {
  background: rgba(148, 163, 184, 0.28);
}

.cloud-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.cloud-button.danger:hover {
  background: rgba(220, 38, 38, 0.18);
}

.dark .cloud-button.secondary {
  background: #1f2937;
  color: var(--text-dark);
  border: 1px solid #374151;
}

.dark .cloud-field span {
  color: #94a3b8;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-emotion-happy {
  background: #fef08a;
  color: #854d0e;
}

.badge-emotion-sad {
  background: #bfdbfe;
  color: #1d4ed8;
}

.badge-emotion-neutral {
  background: #e2e8f0;
  color: #475569;
}

.badge-type {
  background: #ddd6fe;
  color: #4c1d95;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .tree-content {
    padding: 60px 16px 80px;
  }
  .tree-hole button {
    width: 60px;
    height: 60px;
  }
  .chat-header,
  .history-header {
    padding: 16px;
  }
  .chat-body,
  .history-list {
    padding: 18px;
  }
  .history-controls {
    padding: 16px;
  }
  .compose-row {
    align-items: stretch;
  }
  .textarea {
    border-radius: 16px;
  }
}
