:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #14181f;
  --muted: #6b7280;
  --border: #e3e7ef;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --result-pos: #059669;
  --result-neg: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131a;
    --surface: #1a1f2b;
    --text: #edf0f5;
    --muted: #9aa3b2;
    --border: #2a3040;
    --accent: #3b82f6;
    --accent-text: #ffffff;
    --danger: #f87171;
    --result-pos: #34d399;
    --result-neg: #f87171;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding: calc(env(safe-area-inset-top) + 16px) 16px 12px;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.app-main {
  padding: 0 12px 24px;
  max-width: 720px;
  margin: 0 auto;
}

.table-wrap {
  background: var(--surface);
  border-radius: 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

.col-amount, .col-ratio, .col-total, .col-result {
  width: 18%;
}

.col-del {
  width: 36px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  padding: 10px 8px;
  border-radius: 8px;
  min-width: 0;
}

input[type="number"] {
  text-align: right;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}

.total-cell {
  text-align: right;
  padding: 10px 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.total-cell.empty,
.result-cell.empty span.value {
  color: var(--muted);
  opacity: 0.5;
}

.result-cell {
  text-align: right;
  padding: 10px 8px;
  white-space: nowrap;
}

.result-cell span.value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.result-cell.pos span.value {
  color: var(--result-pos);
}

.result-cell.neg span.value {
  color: var(--result-neg);
}

.del-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}

.del-btn:active {
  background: var(--border);
  color: var(--danger);
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.add-btn,
.clear-btn {
  flex: 1;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.add-btn {
  background: var(--accent);
  color: var(--accent-text);
}

.clear-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.add-btn:active,
.clear-btn:active {
  opacity: 0.85;
}
