:root {
  color-scheme: light dark;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  z-index: 100;
}

.login-box {
  width: min(100%, 360px);
  padding: 28px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-box h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.login-tip {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-box input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.login-box button {
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app {
  min-height: 100vh;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.status.ok {
  color: #16a34a;
}

.status.err {
  color: var(--danger);
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

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

.btn-ghost {
  background: transparent;
}

.main {
  padding: 8px 16px 24px;
  max-width: 960px;
  margin: 0 auto;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  padding: 16px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  text-align: center;
  word-break: break-word;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

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

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

.card-name {
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.35;
}

.editor {
  margin-top: 8px;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.editor-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.editor-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.editor-row input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--danger);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.empty-tip {
  margin: 32px 0 0;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .editor-row {
    grid-template-columns: 1fr;
  }

  .btn-icon {
    width: 100%;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
