:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #192233;
  --border: #243044;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --emerald: #10b981;
  --amber: #f59e0b;
  --orange: #f97316;
  --red: #ef4444;
  --radius: 14px;
  --nav-h: 68px;
}

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

html, body {
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.header-inner {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, var(--cyan), var(--emerald));
  color: #061018;
  font-weight: 800;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 8px;
}

.brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.mode-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--cyan);
}

/* Main & Views */
.app-main {
  max-width: 740px;
  margin: 0 auto;
  padding: 14px 14px 24px;
}

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.view.active {
  display: flex;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.hint-tag {
  font-size: 0.72rem;
  color: var(--cyan);
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.25);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Segmented Control */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface-2);
  color: var(--cyan);
}

/* Grids & Fields */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 520px) {
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 11px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus {
  border-color: var(--cyan);
}

.targets-inline {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.targets-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}

.sum-badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
}

.sum-badge.ok {
  color: var(--emerald);
  background: rgba(16, 185, 129, 0.12);
}

.sum-badge.err {
  color: var(--red);
  background: rgba(239, 68, 68, 0.12);
}

/* Upload Boxes */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.upload-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 118px;
  background: var(--bg);
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  padding: 10px;
  transition: border-color 0.15s;
}

.upload-box:hover {
  border-color: var(--cyan);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.upload-icon {
  font-size: 1.5rem;
}

.upload-placeholder strong {
  font-size: 0.8rem;
  color: var(--text);
}

.upload-placeholder small {
  font-size: 0.7rem;
  color: var(--muted);
}

.upload-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.upload-thumbs img {
  width: 58px;
  height: 92px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.upload-count-badge {
  width: 100%;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--cyan);
  margin-top: 2px;
}

/* Buttons */
button, .file-btn {
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
}

button:active {
  transform: scale(0.985);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--emerald));
  color: #061018;
  font-weight: 800;
  font-size: 0.95rem;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
}

.btn-ghost {
  background: transparent;
  color: var(--cyan);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 0.88rem;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.75rem;
}

.btn-block {
  width: 100%;
  display: block;
}

.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.actions-row .btn-secondary {
  flex: 1;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
}

.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 14px; }

.muted-text {
  font-size: 0.78rem;
  color: var(--muted);
}

.status-msg {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--cyan);
}

.status-msg.error {
  color: var(--red);
}

/* Renpho Details */
.renpho-details {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.renpho-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--cyan);
}

/* Result Hero */
.ime-hero {
  text-align: center;
  border-width: 1.5px;
}

.ime-hero.level-perfect,
.ime-hero.level-great {
  border-color: rgba(16, 185, 129, 0.5);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.1), var(--surface));
}

.ime-hero.level-ok {
  border-color: rgba(245, 158, 11, 0.5);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.1), var(--surface));
}

.ime-hero.level-warn,
.ime-hero.level-danger {
  border-color: rgba(239, 68, 68, 0.5);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.1), var(--surface));
}

.ime-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.ime-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.pass-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  color: var(--emerald);
}

.pass-pill.fail {
  background: rgba(239, 68, 68, 0.18);
  color: var(--red);
}

.ime-score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.ime-score {
  font-size: 3.2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.ime-emoji {
  font-size: 2.2rem;
}

.ime-rating-label {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 4px;
}

/* Breakdown */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.bk-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bk-title {
  font-size: 0.74rem;
  color: var(--muted);
}

.bk-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--cyan);
}

.bk-val.penalty {
  color: var(--amber);
}

.bk-item small {
  font-size: 0.7rem;
  color: var(--muted);
}

/* Alert Boxes */
.alert-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cyan);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 10px;
}

.alert-box.ok { border-left-color: var(--emerald); }
.alert-box.warn { border-left-color: var(--amber); }
.alert-box.danger { border-left-color: var(--red); }

.alert-box strong {
  display: block;
  font-size: 0.86rem;
}

.alert-box p {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Chart */
.chart-container {
  width: 100%;
}

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.dot-ime, .dot-weight {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

.dot-ime { background: var(--cyan); }
.dot-weight { background: var(--amber); }

.trend-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-empty {
  text-align: center;
  padding: 24px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* History List */
.filter-pills {
  display: flex;
  gap: 6px;
}

.filter-btn {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.filter-btn.active {
  background: var(--surface-2);
  color: var(--cyan);
  border-color: var(--cyan);
}

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

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.history-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 3px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-score {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--cyan);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(19, 26, 38, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 30;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 16px;
}

.nav-btn.active {
  color: var(--cyan);
}

.nav-icon {
  font-size: 1.2rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--cyan);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
