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

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --danger: #d93025;
  --danger-dark: #b3261e;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#edit-view {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Header */
header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
}

.header-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
  flex-shrink: 0;
}

.header-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

/* List View */
.memo-list {
  flex: 1;
  padding: 8px;
}

.memo-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
}

.memo-item:active {
  background: #e8eaed;
}

.memo-item-content {
  flex: 1;
  min-width: 0;
  pointer-events: none;
}

.memo-item-preview {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.memo-item-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.memo-item-delete {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.memo-item-delete:hover,
.memo-item-delete:active {
  background: #fce8e6;
  color: var(--danger);
}

/* Swipe delete background */
.memo-item-swipe-bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  background: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0 var(--radius) var(--radius) 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.memo-item.swiping .memo-item-swipe-bg {
  opacity: 1;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 16px;
}

.empty-state .sub {
  font-size: 13px;
  margin-top: 8px;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  z-index: 5;
}

.fab:active {
  background: var(--primary-dark);
  transform: scale(0.95);
}

/* Edit View */
.edit-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

#memo-text {
  flex: 1;
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  background: var(--surface);
}

#memo-text:focus {
  border-color: var(--primary);
}

.char-count {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
  padding: 0 4px;
  margin-top: -4px;
}

.edit-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.action-btn:active {
  background: #e8f0fe;
}

.action-btn-x {
  background: #000;
  color: #fff;
  border-color: #000;
}

.action-btn-x:active {
  background: #333;
}

.edit-main-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #e8eaed;
  color: var(--text);
}

.btn-secondary:active {
  background: #dadce0;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:active {
  background: var(--danger-dark);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s;
}

.toast.hidden {
  display: block !important;
  opacity: 0;
  pointer-events: none;
}

.toast:not(.hidden) {
  opacity: 1;
}

/* Delete Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.dialog {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.dialog p {
  font-size: 16px;
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.dialog-actions .btn {
  flex: unset;
  padding: 10px 20px;
}

/* Settings View */
.settings-container {
  padding: 8px;
}

.settings-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-item-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.settings-item-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 4px;
  bottom: 4px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Settings Footer */
.settings-footer {
  padding: 24px 16px;
  text-align: center;
}

.settings-version {
  font-size: 13px;
  color: var(--text-secondary);
}
