*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #2c2c2c;
  --text-muted: #6b6b6b;
  --accent: #3d7a8a;
  --accent-hover: #2f6270;
  --border: #e0ddd6;
  --error-bg: #fef2f2;
  --error-text: #9b2c2c;
  --error-border: #fecaca;
  --notice-bg: #fffbeb;
  --notice-text: #92400e;
  --notice-border: #fde68a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.tagline {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 0.25rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem;
  margin-bottom: 1rem;
}

.tab {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.text-input,
.url-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input {
  min-height: 200px;
}

.text-input:focus,
.url-input:focus,
.mode-select:focus,
.explain-btn:focus,
.tab:focus,
.link-btn:focus,
.remove-btn:focus,
.copy-btn:focus,
.listen-btn:focus,
.modal-close-btn:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 122, 138, 0.15);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(61, 122, 138, 0.04);
}

.dropzone-text {
  color: var(--text);
  font-size: 0.95rem;
}

.dropzone-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.link-btn:hover {
  color: var(--accent-hover);
}

.file-preview {
  position: relative;
  display: inline-block;
}

.file-preview img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 6px;
  display: block;
}

.pdf-preview {
  text-align: left;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border-radius: 6px;
  min-width: 200px;
}

.pdf-preview-icon {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--surface);
  background: #c0392b;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.pdf-preview-name {
  font-size: 0.95rem;
  font-weight: 500;
  word-break: break-all;
}

.pdf-preview-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover {
  color: var(--error-text);
  border-color: var(--error-border);
}

.error-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.notice-banner {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--notice-bg);
  color: var(--notice-text);
  border: 1px solid var(--notice-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.controls {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mode-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.mode-select {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
}

.explain-btn {
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.explain-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.explain-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.output-section {
  margin-top: 2rem;
}

.output-actions {
  margin-top: 0.75rem;
}

.listen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.listen-btn:hover:not(:disabled) {
  background: rgba(61, 122, 138, 0.06);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.listen-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.listen-btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(61, 122, 138, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.output-wrapper {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.copy-btn:hover {
  opacity: 1;
  color: var(--text);
  background: rgba(0, 0, 0, 0.04);
}

.copy-btn.copied {
  opacity: 1;
  color: var(--accent);
}

.copy-btn-icon {
  flex-shrink: 0;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.loading-dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 4.5rem 1.5rem 1.5rem;
  box-shadow: var(--shadow);
}

.output h2 {
  font-size: 1.35rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.output h3 {
  font-size: 1.05rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.output p {
  margin-bottom: 0.75rem;
}

.output ul,
.output ol {
  margin-bottom: 0.75rem;
  padding-left: 1.5rem;
}

.output li {
  margin-bottom: 0.35rem;
}

.output code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.output pre {
  background: var(--bg);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 0.75rem;
}

.output pre code {
  background: none;
  padding: 0;
}

.footer {
  text-align: center;
  margin-top: 3rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.4);
}

.modal-card {
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

.modal-card audio {
  width: 100%;
  margin-bottom: 1rem;
}

.modal-error {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.modal-close-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background: rgba(61, 122, 138, 0.06);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .container {
    padding: 1.5rem 1rem 2rem;
  }

  .tabs {
    flex-direction: column;
  }

  .tab {
    text-align: center;
  }
}
