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

:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --ui-muted: #888888;
  --ui-hover: #444444;
  --ui-border: rgba(0, 0, 0, 0.08);
  --fade-duration: 10s;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-blur: 12px;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
}

[data-theme="dark"] {
  --bg: #0d0d0d;
  --text: #e8e8e8;
  --ui-muted: #555555;
  --ui-hover: #999999;
  --ui-border: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(13, 13, 13, 0.85);
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  transition: background 0.4s ease, color 0.4s ease;
}

/* ── Hover zone ── */

#top-hover-zone {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  z-index: 99;
}

/* ── Menu bar ── */

#menu-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--ui-border);
  z-index: 100;
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
              transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

#menu-bar.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.menu-left {
  display: flex;
  align-items: center;
}

#logo {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text);
  opacity: 0.7;
  user-select: none;
  transition: opacity 0.2s ease;
}

#menu-bar:hover #logo {
  opacity: 1;
}

.menu-right {
  display: flex;
  align-items: center;
  gap: 28px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
}

.menu-item label {
  color: var(--ui-muted);
  user-select: none;
  font-weight: 400;
}

/* Limit input - modern pill style */
#limit-input {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
  border: 1.5px solid transparent;
  border-radius: 20px;
  padding: 6px 12px;
  width: 10ch;
  text-align: center;
  caret-color: var(--accent);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] #limit-input {
  background: rgba(255, 255, 255, 0.05);
}

#limit-input:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: var(--ui-border);
}

[data-theme="dark"] #limit-input:hover {
  background: rgba(255, 255, 255, 0.08);
}

#limit-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] #limit-input:focus {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

/* Mode toggle - modern pill button */
#mode-btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
  border: 1.5px solid transparent;
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] #mode-btn {
  background: rgba(255, 255, 255, 0.05);
}

#mode-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: var(--ui-border);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] #mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#mode-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Theme toggle - modern pill button */
#theme-btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
  border: 1.5px solid transparent;
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] #theme-btn {
  background: rgba(255, 255, 255, 0.05);
}

#theme-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: var(--ui-border);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] #theme-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#theme-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ── Writing area ── */

#editor {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  padding: 12vh 18vw 12vh 18vw;
  background: var(--bg);
  border: none;
  outline: none;
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(1.15rem, 2.4vw, 1.6rem);
  line-height: 2;
  caret-color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  scroll-behavior: smooth;
  scroll-padding-bottom: 12vh;
  scrollbar-width: none;
  transition: opacity var(--fade-duration) ease, color 0.4s ease;
}

#editor::-webkit-scrollbar {
  display: none;
}

/* Placeholder */
#editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ui-muted);
  font-style: italic;
  opacity: 0.6;
  pointer-events: none;
}

#editor:focus {
  outline: none;
}

/* Fade state */
#editor.fading {
  opacity: 0;
}

/* ── Word count - modern badge style ── */

#wordcount {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ui-muted);
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--ui-border);
  border-radius: 24px;
  padding: 8px 16px;
  min-width: 50px;
  text-align: center;
  user-select: none;
  pointer-events: none;
  opacity: 0.7;
  transform: scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

#wordcount.active {
  opacity: 1;
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] #wordcount.active {
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.25);
}

/* ── Word count container with download button ── */

#wordcount-container {
  position: fixed;
  bottom: 28px;
  right: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

#site-meta {
  position: fixed;
  left: 50%;
  bottom: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(calc(100vw - 64px), 780px);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  color: var(--ui-muted);
  opacity: 0.55;
  z-index: 10;
  pointer-events: auto;
  user-select: none;
  transform: translateX(-50%);
  justify-content: center;
  text-align: center;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#site-meta.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
}

#site-meta a {
  color: inherit;
  text-decoration: none;
  text-transform: lowercase;
  font-weight: 600;
}

#site-meta a:hover {
  color: var(--text);
  opacity: 1;
}

#site-meta span {
  white-space: nowrap;
}

/* Download button - bottom (stacked under word count) */
#download-btn-bottom {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95) translateY(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2), 0 1px 2px rgba(0, 0, 0, 0.08);
}

#download-btn-bottom.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

#download-btn-bottom:hover {
  background: var(--accent-hover);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 12px rgba(59, 130, 246, 0.3), 0 2px 4px rgba(0, 0, 0, 0.1);
}

#download-btn-bottom:active {
  transform: translateY(0) scale(1);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

/* ── Responsive ── */

@media (max-width: 768px) {
  #menu-bar {
    padding: 0 16px;
    height: 56px;
  }
  
  .menu-right {
    gap: 12px;
  }
  
  #limit-input {
    padding: 5px 10px;
    width: 8ch;
  }
  
  #theme-btn {
    padding: 5px 12px;
  }
  
  #download-btn {
    padding: 6px 14px;
  }
  
  #editor {
    padding: 10vh 10vw 10vh 10vw;
    font-size: clamp(1.05rem, 4.5vw, 1.35rem);
    line-height: 1.9;
  }
  
  #wordcount-container {
    bottom: 20px;
    right: 20px;
  }

  #site-meta {
    left: 50%;
    bottom: 20px;
    max-width: min(calc(100vw - 40px), 720px);
    font-size: 0.62rem;
    gap: 10px;
    transform: translateX(-50%);
  }
  
  #wordcount {
    padding: 6px 12px;
    font-size: 0.7rem;
  }
  
  #download-btn-bottom {
    padding: 6px 14px;
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  #logo {
    display: none;
  }
  
  .menu-right {
    gap: 8px;
  }
  
  .menu-item label {
    display: none;
  }
  
  #limit-input {
    width: 8ch;
  }
  
  #editor {
    padding: 8vh 8vw 8vh 8vw;
  }
  
  #wordcount-container {
    bottom: 16px;
    right: 16px;
  }

  #site-meta {
    left: 50%;
    bottom: 16px;
    max-width: calc(100vw - 32px);
    font-size: 0.56rem;
    gap: 8px;
    flex-wrap: wrap;
    line-height: 1.2;
    transform: translateX(-50%);
  }

  #site-meta span {
    white-space: normal;
  }
}
