/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.12);
  --primary-border: rgba(37, 99, 235, 0.28);

  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.12);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --surface: rgba(241, 245, 249, 0.92);
  --surface-elevated: rgba(255, 255, 255, 0.97);
  --surface-hover: rgba(226, 232, 240, 0.95);
  --border: rgba(15, 40, 80, 0.1);
  --border-strong: rgba(15, 40, 80, 0.16);
  --shadow-sm: 0 1px 3px rgba(15, 40, 80, 0.08);
  --shadow-md: 0 4px 16px rgba(15, 40, 80, 0.1);
  --shadow-lg: 0 8px 32px rgba(15, 40, 80, 0.14);

  --header-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --bg-gradient-start: #dbeafe;
  --bg-gradient-mid: #bfdbfe;
  --bg-gradient-end: #eff6ff;
  --bg-glow: rgba(37, 99, 235, 0.2);
  --bg-glow-secondary: rgba(59, 130, 246, 0.12);
}

body.dark {
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --surface: rgba(12, 22, 42, 0.82);
  --surface-elevated: rgba(16, 28, 52, 0.92);
  --surface-hover: rgba(22, 38, 68, 0.88);
  --border: rgba(100, 149, 237, 0.18);
  --border-strong: rgba(100, 149, 237, 0.28);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background:
    radial-gradient(ellipse 130% 90% at 15% -10%, var(--bg-glow) 0%, transparent 58%),
    radial-gradient(ellipse 110% 70% at 90% 110%, var(--bg-glow-secondary) 0%, transparent 52%),
    linear-gradient(165deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 45%, var(--bg-gradient-end) 100%);
  background-attachment: fixed;
  transition: color 0.35s ease;
  min-height: 100vh;
}

body.dark {
  background:
    radial-gradient(ellipse 120% 85% at 10% -5%, var(--bg-glow) 0%, transparent 55%),
    radial-gradient(ellipse 100% 75% at 95% 105%, var(--bg-glow-secondary) 0%, transparent 50%),
    radial-gradient(ellipse 80% 50% at 50% 50%, var(--bg-glow) 0%, transparent 70%),
    linear-gradient(165deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 40%, var(--bg-gradient-end) 100%);
}

/* Layout */
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--surface-elevated);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: var(--header-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
  cursor: pointer;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.nav-button:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.nav-button.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.nav-button-icon {
  padding: 0.5rem 0.625rem;
}

.nav-button-icon svg {
  display: block;
}

.nav-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.4375rem;
  border-radius: 999px;
  min-width: 1.125rem;
  text-align: center;
  line-height: 1.4;
}

.nav-badge.hidden {
  display: none;
}

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: calc(var(--header-height) + 2rem) auto 2rem;
  padding: 0 1.5rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.toolbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
}

/* Buttons */
.icon-button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
  color: var(--primary);
}

.icon-button svg {
  color: currentColor;
}

.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 40%, transparent);
}

.btn-add {
  background: var(--surface-elevated);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  box-shadow: var(--shadow-sm);
}

.btn-add:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-hover);
}

body.dark .btn-primary {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 30%, transparent);
}

body.dark.accent-black .btn-primary,
body.dark.accent-white .btn-primary,
body.dark.accent-yellow .btn-primary {
  color: #171717;
}

.btn-secondary {
  background: var(--surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--primary-border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.btn-reset {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  box-shadow: var(--shadow-sm);
}

.btn-reset:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-sm {
  padding: 0.4375rem 0.875rem;
  font-size: 0.8125rem;
}

.btn-back {
  background: var(--surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.btn-back:not(.btn-compact) {
  margin-bottom: 1.25rem;
}

.btn-back:hover {
  border-color: var(--primary-border);
  background: var(--surface-hover);
}

.btn svg {
  flex-shrink: 0;
}

#sortSelect {
  padding: 0.625rem 2rem 0.625rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
}

#sortSelect:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Search Bar */
.search-bar {
  flex: 1;
  position: relative;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  background: var(--surface-elevated);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Sections */
.section {
  margin-bottom: 1.5rem;
}

.section.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}

.section h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.section-header h2 {
  margin-bottom: 0;
}

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* Memo Card */
.memo-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.memo-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-border);
}

.memo-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 0.375rem;
}

.memo-card-title {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
  padding-right: 2rem;
  color: var(--text-primary);
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
}

.memo-pin-icon {
  flex-shrink: 0;
  color: var(--primary);
}

.edit-content a.memo-link {
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
}

.edit-content a.memo-link:hover {
  color: #1d4ed8;
}

body.dark .edit-content a.memo-link {
  color: #60a5fa;
}

body.dark .edit-content a.memo-link:hover {
  color: #93c5fd;
}

.memo-card-date {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.memo-card-menu {
  position: absolute;
  top: 2.75rem;
  right: 0.75rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  overflow: hidden;
  min-width: 160px;
}

.memo-card-menu button {
  width: 100%;
  padding: 0.625rem 1rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: background-color 0.15s ease;
}

.memo-card-menu button:hover {
  background: var(--primary-light);
}

.memo-card-menu button.danger {
  color: var(--danger);
}

.memo-card-menu button.danger:hover {
  background: var(--danger-light);
}

.memo-card-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  opacity: 1;
  transition: background 0.15s ease, color 0.15s ease;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.memo-card-menu-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* Group Card */
.group-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  position: relative;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.group-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-border);
}

.group-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.group-card-info-wrap {
  flex: 1;
  min-width: 0;
}

.group-card-title-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.group-card-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.group-card-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 0.25rem;
}

.group-card-menu {
  position: absolute;
  top: 2.75rem;
  right: 0.75rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  overflow: hidden;
  min-width: 160px;
}

.group-card-menu button {
  width: 100%;
  padding: 0.625rem 1rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: background-color 0.15s ease;
}

.group-card-menu button:hover {
  background: var(--primary-light);
}

.group-card-menu button.danger {
  color: var(--danger);
}

.group-card-menu button.danger:hover {
  background: var(--danger-light);
}

.group-card-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  opacity: 1;
  transition: background 0.15s ease, color 0.15s ease;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.group-card-menu-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.group-memos {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.group-memo-item {
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 2rem 0.625rem 0.875rem;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
}

.group-memo-item:hover {
  background: var(--primary-border);
  border-color: var(--primary);
}

.group-memo-title {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.group-memo-remove {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--text-muted);
  transition: color 0.15s ease, background 0.15s ease;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
}

.group-memo-remove:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  background: var(--primary-light);
  border-radius: var(--radius-md);
  border: 1px dashed var(--primary-border);
  grid-column: 1 / -1;
}

/* Trash Cards */
.trash-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.trash-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-border);
}

.trash-card-header {
  margin-bottom: 0.375rem;
}

.trash-card-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.trash-card-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.trash-card-expiry {
  font-size: 0.8125rem;
  color: var(--danger);
  font-weight: 500;
  margin-bottom: 1rem;
}

.trash-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Page Info */
.page-info {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-lg);
}

.page-info svg {
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.page-info p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Confirm Card */
.confirm-card {
  text-align: center;
  max-width: 400px;
}

.confirm-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  background: var(--danger-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
}

.confirm-card h3 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.confirm-message {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.confirm-actions {
  justify-content: center;
}

/* Edit View */
#editView {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-width: 960px;
  position: relative;
}

.edit-tool-float-layer {
  display: none;
}

.reorderable-tool-btn {
  touch-action: none;
}

.reorderable-tool-btn.dragging {
  opacity: 0.55;
  cursor: grabbing;
  z-index: 5;
}

.reorderable-tool-btn.drag-over {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
}

.edit-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.25rem 0 0.5rem;
}

.edit-reset-btn {
  margin-left: auto;
  flex-shrink: 0;
}

.settings-label {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.settings-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.accent-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 0.625rem;
}

.accent-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.accent-option:hover {
  border-color: var(--primary-border);
  color: var(--primary);
}

.accent-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.accent-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow-sm);
}

.accent-blue .accent-swatch { background: #2563eb; }
.accent-purple .accent-swatch { background: #9333ea; }
.accent-green .accent-swatch { background: #16a34a; }
.accent-cyan .accent-swatch { background: #06b6d4; }
.accent-red .accent-swatch { background: #dc2626; }
.accent-yellow .accent-swatch { background: #eab308; }
.accent-black .accent-swatch { background: #171717; }
.accent-white .accent-swatch {
  background: #f8fafc;
  border-color: rgba(15, 40, 80, 0.18);
}

.accent-swatch-rainbow {
  background: linear-gradient(135deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #9333ea);
  animation: rainbow-swatch-spin 3s linear infinite;
}

@keyframes rainbow-swatch-spin {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

body.accent-rainbow #logoBtn {
  animation: rainbow-text-hue 4s linear infinite;
}

@keyframes rainbow-text-hue {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

.edit-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-compact {
  padding: 0.4375rem 0.875rem;
  font-size: 0.8125rem;
  margin-bottom: 0;
}

.btn-compact svg {
  width: 16px;
  height: 16px;
}

.icon-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-tool-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.icon-tool-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.icon-tool-btn-text {
  font-size: 1rem;
  font-weight: 700;
  font-family: Georgia, 'Times New Roman', serif;
}

.tool-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 0.25rem;
  white-space: nowrap;
}

.text-size-btn,
.text-weight-btn,
.text-deco-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.text-deco-btn {
  min-width: 2.25rem;
  font-family: Georgia, 'Times New Roman', serif;
  font-style: normal;
}

.text-deco-btn .deco-u {
  text-decoration: underline;
}

.text-deco-btn .deco-s {
  text-decoration: line-through;
}

.text-size-btn:hover,
.text-weight-btn:hover,
.text-deco-btn:hover {
  border-color: var(--primary-border);
  color: var(--primary);
}

.text-size-btn.active,
.text-weight-btn.active,
.text-deco-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

#drawDuplicateBtn:disabled,
#drawDeleteStrokeBtn:disabled,
#rotateImageLeftBtn:disabled,
#rotateImageRightBtn:disabled,
#bringImageFrontBtn:disabled,
#sendImageBackBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.text-color-btn {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.text-color-default {
  background: var(--text-primary);
  border-color: var(--border-strong);
}

.text-color-btn:hover {
  transform: scale(1.1);
}

.text-color-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.text-color-white {
  border-color: var(--border-strong);
}

.brush-cursor {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--primary);
  border-radius: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  transition: width 0.05s ease, height 0.05s ease, border-color 0.1s ease;
  left: 0;
  top: 0;
}

.brush-cursor.hidden {
  display: none;
}

.draw-tools-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.draw-tool-group {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.draw-tool-btn,
.draw-size-btn,
.draw-history-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.draw-size-btn {
  border-radius: 50%;
  padding: 0;
}

.draw-history-btn {
  border-radius: var(--radius-sm);
}

.draw-history-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.draw-tool-btn:hover,
.draw-size-btn:hover:not(:disabled),
.draw-history-btn:hover:not(:disabled) {
  border-color: var(--primary-border);
  color: var(--primary);
}

.draw-tool-btn.active,
.draw-size-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.size-dot {
  border-radius: 50%;
  background: var(--text-primary);
  display: block;
  flex-shrink: 0;
}

.draw-size-btn.active .size-dot {
  background: var(--primary);
}

.draw-color-btn {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.draw-color-white {
  border-color: var(--border-strong);
}

.draw-color-btn:hover {
  transform: scale(1.1);
}

.draw-color-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.edit-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.edit-paper {
  position: relative;
  flex: 1;
  min-height: calc(100vh - 280px);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
}

.edit-paper.draw-mode .edit-content {
  pointer-events: none;
}

.edit-paper.image-mode .edit-content {
  pointer-events: none;
}

.image-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.edit-paper.image-mode .image-layer {
  pointer-events: auto;
}

.memo-image-wrap {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: var(--radius-sm);
  user-select: none;
  touch-action: none;
}

.memo-image-wrap.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.memo-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.edit-paper.image-mode .memo-image-wrap {
  cursor: grab;
}

.edit-paper.image-mode .memo-image-wrap.dragging {
  cursor: grabbing;
  opacity: 0.85;
}

.memo-image-resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 3px;
  cursor: nwse-resize;
  display: none;
  box-shadow: var(--shadow-sm);
}

.edit-paper.image-mode .memo-image-wrap.selected .memo-image-resize-handle {
  display: block;
}

#deleteImageBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tool-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.hidden-input {
  display: none;
}

#drawCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
  z-index: 3;
}

#drawCanvas.active {
  pointer-events: auto;
  cursor: none;
}

.edit-title {
  width: 100%;
  padding: 0.75rem;
  border: none;
  font-size: 1.5rem;
  font-weight: 700;
  background: transparent;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
  letter-spacing: -0.02em;
}

.edit-title:focus {
  outline: none;
  background: var(--primary-light);
}

.edit-content {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 280px);
  padding: 0.75rem;
  border: none;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-primary);
  resize: none;
  font-family: inherit;
  line-height: 1.75;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.edit-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.edit-content:focus {
  outline: none;
  background: var(--primary-light);
}

body.dark .edit-content span[style*="#0f172a"],
body.dark .edit-content span[style*="#0F172A"],
body.dark .edit-content span[style*="rgb(15, 23, 42)"],
body.dark .edit-content a.memo-link[style*="#0f172a"],
body.dark .edit-content a.memo-link[style*="rgb(15, 23, 42)"] {
  color: var(--text-primary) !important;
}

.edit-paper.draw-mode .edit-content:focus {
  background: transparent;
}

.auto-save-hint {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--primary-light);
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  display: inline-block;
  margin: 0 auto;
  border: 1px solid var(--primary-border);
}

#editView .auto-save-hint {
  align-self: center;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(7, 21, 37, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-large {
  max-width: 480px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.modal input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  background: var(--surface);
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.625rem;
}

.memo-select-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.memo-select-list::-webkit-scrollbar {
  width: 5px;
}

.memo-select-list::-webkit-scrollbar-track {
  background: transparent;
}

.memo-select-list::-webkit-scrollbar-thumb {
  background: var(--primary-border);
  border-radius: 3px;
}

.memo-select-item {
  padding: 0.75rem 1rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.memo-select-item:hover {
  background: var(--primary-border);
  border-color: var(--primary);
}

/* Drag and Drop */
.draggable-card {
  touch-action: pan-y;
}

body.drag-active {
  user-select: none;
  cursor: grabbing;
}

body.drag-active .draggable-card {
  cursor: grabbing;
}

.draggable-card.dragging {
  opacity: 0.55;
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  position: relative;
  cursor: grabbing;
}

.draggable-card.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.modal-search {
  margin-bottom: 1rem;
}

.modal-search input {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Utility Classes */
.hidden {
  display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
  header {
    padding: 0 1rem;
  }

  header h1 {
    font-size: 1.125rem;
  }

  .header-nav {
    gap: 0.375rem;
  }

  .nav-button {
    padding: 0.4375rem 0.625rem;
    font-size: 0;
    gap: 0;
  }

  .nav-button svg {
    margin: 0;
  }

  .nav-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.625rem;
    padding: 0.0625rem 0.3125rem;
  }

  main {
    margin-top: calc(var(--header-height) + 1.25rem);
    padding: 0 1rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
  }

  .toolbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #sortSelect {
    width: 100%;
  }

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

  .section.panel {
    padding: 1.25rem;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .section-header .btn {
    justify-content: center;
  }

  .modal-content {
    padding: 1.25rem;
  }

  .edit-content {
    min-height: calc(100vh - 240px);
  }

  .edit-paper {
    min-height: calc(100vh - 240px);
  }

  .draw-tools-panel {
    gap: 0.625rem;
    padding: 0.625rem;
  }

  .trash-card-actions {
    flex-direction: column;
  }

  .trash-card-actions .btn {
    justify-content: center;
  }

  .confirm-actions {
    flex-direction: column-reverse;
  }

  .confirm-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .edit-container {
    padding: 1.25rem;
  }
}
