:root {
  --primary: #512BD4;
  --ok: #1E7B34;
  --ng: #C62828;
  --bg: #F4F5F9;
  --card: #FFFFFF;
  --text: #1D1D28;
  --muted: #6B6B7B;
  --border: #D8D8E2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121219;
    --card: #1E1E2A;
    --text: #F2F2F7;
    --muted: #A0A0B0;
    --border: #34344A;
    --ok: #5BD17A;
    --ng: #FF7B7B;
  }
}

:root[data-theme="dark"] {
  --bg: #121219;
  --card: #1E1E2A;
  --text: #F2F2F7;
  --muted: #A0A0B0;
  --border: #34344A;
  --ok: #5BD17A;
  --ng: #FF7B7B;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Malgun Gothic", sans-serif;
  font-size: 16px;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--primary);
  color: #fff;
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 18px;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

.view {
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 24px);
}

.card {
  display: block;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}

input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  min-height: 44px;
}

.search {
  margin: 0 0 10px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item-list li {
  display: block;
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
}

.item-list li:active { opacity: 0.7; }

.code {
  font-family: Consolas, monospace;
  font-weight: 700;
  color: var(--primary);
}

.name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.item-head img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}

.field {
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.field-name { font-weight: 700; }

.field-range {
  font-size: 13px;
  color: var(--muted);
}

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}

.badge.ok { background: var(--ok); }
.badge.ng { background: var(--ng); }
.badge.none { background: var(--muted); }

.field.ok input { border-color: var(--ok); }
.field.ng input { border-color: var(--ng); }

.primary {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 8px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.primary:disabled { opacity: 0.5; }

.msg {
  min-height: 1.2em;
  font-size: 14px;
  color: var(--ng);
}

.lang-select {
  width: auto;
  min-height: 36px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 8px;
  border: 0;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 14px;
}

.lang-select option { color: #111; }

.section-title {
  margin: 0 0 12px;
  font-size: 18px;
}

.secondary {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.link {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}

.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 8px; }
.center { text-align: center; }

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu-card {
  display: block;
  margin-bottom: 10px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
}

.menu-card:active { opacity: 0.7; }
.menu-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }

.suggest {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.suggest li {
  display: block;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  overflow-wrap: anywhere;
}

.suggest li:last-child { border-bottom: 0; }
.suggest li:active { background: var(--bg); }

.field-range { margin: 4px 0 6px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  padding: 14px;
  border-radius: 12px;
  background: #222;
  color: #fff;
  text-align: center;
  z-index: 20;
}
