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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #555;
  --muted: #888;
  --border: #ddd;
  --border-focus: #999;
  --selection: #b4d5fe;
  --btn-bg: #1a1a1a;
  --btn-text: #fff;
  --btn-hover: #333;
  --code-bg: #fff;
  --gutter-bg: #f5f5f5;
  --gutter-text: #bbb;
  --link-color: #1a1a1a;
  --toast-bg: #1a1a1a;
  --toast-text: #fff;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #1e1e1e;
  --surface: #252525;
  --text: #d4d4d4;
  --text-secondary: #aaa;
  --muted: #666;
  --border: #3a3a3a;
  --border-focus: #666;
  --selection: #264f78;
  --btn-bg: #d4d4d4;
  --btn-text: #1e1e1e;
  --btn-hover: #e0e0e0;
  --code-bg: #1e1e1e;
  --gutter-bg: #2a2a2a;
  --gutter-text: #555;
  --link-color: #d4d4d4;
  --toast-bg: #d4d4d4;
  --toast-text: #1e1e1e;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--selection);
}

a {
  color: var(--link-color);
}

/* ---- Top Bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-logo {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--text);
  text-decoration: none;
  user-select: none;
}

.topbar-logo:hover {
  color: var(--text);
}

.topbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* ---- Main Content ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---- Sender: Editor ---- */
.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0;
}

.editor textarea {
  flex: 1;
  width: 100%;
  min-height: calc(100vh - 48px - 44px - 42px);
  padding: 1.25rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  border: none;
  outline: none;
  background: var(--code-bg);
  color: var(--text);
  resize: none;
  tab-size: 4;
}

.editor textarea::placeholder {
  color: var(--muted);
}

.editor textarea::selection {
  background: var(--selection);
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 42px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.editor-stats {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
  user-select: none;
}

.editor-stats span + span::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border);
  vertical-align: middle;
  margin-right: 1rem;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-clear {
  padding: 0.3rem 0.6rem;
  font-size: 0.7rem;
  font-family: var(--font);
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-clear:hover {
  color: var(--text);
  border-color: var(--border);
}

.btn-share {
  padding: 0.35rem 1rem;
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 600;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-share:hover {
  background: var(--btn-hover);
}

.btn-share:disabled {
  opacity: 0.4;
  cursor: default;
}

.shortcut-hint {
  font-size: 0.65rem;
  color: var(--muted);
  font-family: var(--mono);
  margin-left: 0.25rem;
}

/* ---- Sender: Result ---- */
.result-area {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  animation: none;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.result-area .result-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex-shrink: 0;
}

.result-area input {
  flex: 1;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.35rem 0.6rem;
  outline: none;
}

.result-area input:focus {
  border-color: var(--border-focus);
}

.btn-copy {
  padding: 0.35rem 0.75rem;
  font-size: 0.7rem;
  font-family: var(--font);
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.btn-copy:hover {
  border-color: var(--border-focus);
  background: var(--bg);
}

.btn-copy.copied {
  color: #2a9d4e;
  border-color: #2a9d4e;
}

/* ---- Receive PIN Area ---- */
.pin-receive-container {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: 0.5rem;
  border-right: 1px solid var(--border);
  padding-right: 0.75rem;
}

.pin-input {
  width: 120px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.25rem 0.5rem;
  outline: none;
  text-align: center;
  letter-spacing: 0.1em;
}

.pin-input::placeholder {
  letter-spacing: normal;
  color: var(--muted);
}

.pin-input:focus {
  border-color: var(--border-focus);
}

.btn-receive {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 600;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-receive:hover {
  background: var(--btn-hover);
}

/* ---- QR Code Container ---- */
.qr-container {
  margin-left: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.qr-img {
  width: 120px;
  height: 120px;
  display: block;
}

.qr-label {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.4rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* ---- Receiver: View ---- */
.view-page {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.view-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
}

.view-meta span + span::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border);
  vertical-align: middle;
  margin-right: 1rem;
}

.view-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.view-btn {
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
  font-family: var(--font);
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.view-btn:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

.view-btn.primary {
  background: var(--btn-bg);
  color: var(--btn-text);
  border-color: var(--btn-bg);
}

.view-btn.primary:hover {
  background: var(--btn-hover);
  border-color: var(--btn-hover);
  color: var(--btn-text);
}

.code-area {
  flex: 1;
  display: flex;
  overflow: auto;
  background: var(--code-bg);
  -webkit-overflow-scrolling: touch;
}

.line-numbers {
  padding: 1.25rem 0.75rem 1.25rem 1rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--gutter-text);
  text-align: right;
  user-select: none;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--gutter-bg);
}

.paste-content {
  padding: 1.25rem 1.5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre;
  word-wrap: normal;
  overflow-x: auto;
  margin: 0;
  flex: 1;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.paste-content.wrap {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Footer ---- */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.5rem;
  height: 32px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.footer p {
  font-size: 0.65rem;
  color: var(--muted);
}

/* ---- 404 Page ---- */
.not-found {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.not-found h2 {
  font-size: 3rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.not-found p {
  font-size: 0.85rem;
  color: var(--muted);
}

.not-found a {
  margin-top: 0.5rem;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 0.4rem 0.9rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Expiration Select ---- */
.expire-select {
  font-size: 0.7rem;
  font-family: var(--font);
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.25rem 0.4rem;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.expire-select:hover {
  border-color: var(--border-focus);
  color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .topbar {
    padding: 0 1rem;
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    gap: 0.5rem;
  }
  .topbar-subtitle {
    display: none;
  }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .pin-receive-container {
    flex: 1;
    margin-right: 0;
    padding-right: 0;
    border-right: none;
  }
  .pin-input {
    width: 100%;
    max-width: none;
  }
  .theme-toggle {
    width: 40px;
    height: 40px;
  }
  .theme-toggle svg {
    width: 18px;
    height: 18px;
  }
  .editor textarea {
    padding: 1rem;
    font-size: 16px;
    min-height: calc(100vh - 52px - 100px - 42px);
  }
  .editor-bar {
    flex-wrap: wrap;
    padding: 0.5rem 1rem;
    height: auto;
    gap: 0.4rem;
  }
  .editor-stats {
    font-size: 0.75rem;
    width: 100%;
    justify-content: flex-start;
  }
  .editor-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 0.5rem;
  }
  .btn-clear {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    min-height: 36px;
  }
  .btn-share {
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    min-height: 36px;
  }
  .expire-select {
    font-size: 0.8rem;
    padding: 0.4rem 0.5rem;
    min-height: 36px;
  }
  .result-area {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    flex-direction: column;
    align-items: stretch;
  }
  .result-row {
    flex-wrap: wrap;
  }
  .result-area .result-label {
    width: 100%;
    margin-bottom: 0.25rem;
  }
  .result-area input {
    font-size: 16px;
  }
  .qr-container {
    width: 100%;
    margin-left: 0;
    margin-top: 1rem;
  }
  .btn-copy {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    min-height: 36px;
  }
  .shortcut-hint {
    display: none;
  }
  .view-header {
    padding: 0 1rem;
    flex-direction: column;
    align-items: flex-start;
    height: auto;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    gap: 0.5rem;
  }
  .view-meta {
    font-size: 0.75rem;
    width: 100%;
  }
  .view-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .view-btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    min-height: 36px;
  }
  .view-btn.primary {
    padding: 0.4rem 0.85rem;
  }
  .code-area {
    flex-direction: column;
  }
  .line-numbers {
    display: none;
  }
  .paste-content {
    padding: 1rem;
    font-size: 14px;
  }
  .footer {
    padding: 0 1rem;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .footer p {
    font-size: 0.7rem;
  }
  .toast {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  .editor-stats .stat-words,
  .editor-stats .stat-lines {
    display: none;
  }
  .editor-stats {
    font-size: 0.7rem;
  }
  .editor textarea {
    font-size: 16px;
    padding: 0.75rem;
  }
  .editor-bar {
    padding: 0.5rem 0.75rem;
  }
  .btn-share {
    padding: 0.5rem 1rem;
    flex: 1;
  }
  .view-btn {
    font-size: 0.75rem;
    padding: 0.35rem 0.55rem;
  }
  .paste-content {
    font-size: 13px;
  }
}
