:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #f7faff;
  --panel-strong: #edf4ff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d7e3f1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #047857;
  --success-soft: #d1fae5;
  --shadow-sm: 0 6px 16px rgba(15, 23, 42, 0.05);
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

html[data-theme="DARK"] {
  --bg: #0b1220;
  --panel: #111827;
  --panel-soft: #162033;
  --panel-strong: #1b2942;
  --text: #e5eefc;
  --muted: #94a3b8;
  --line: #24324a;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-soft: #1d4ed8;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.22);
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.06), transparent 32%),
    radial-gradient(circle at top right, rgba(96, 165, 250, 0.06), transparent 26%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

body {
  max-width: 680px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 16px)
    12px
    calc(env(safe-area-inset-bottom) + 24px);
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    opacity 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

button:hover:not(:disabled) {
  opacity: 0.96;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  pointer-events: none;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  min-height: 46px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input::placeholder {
  color: var(--muted);
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 18px;
  background: linear-gradient(180deg, var(--panel), var(--panel-soft));
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
}

.header-title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.status-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.tabs-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

html[data-theme="DARK"] .tabs-container {
  background: rgba(17, 24, 39, 0.7);
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tab-row:last-child {
  grid-template-columns: repeat(3, 1fr);
}

.tab-btn {
  min-height: 44px;
  padding: 10px 8px;
  border-radius: 14px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 0.92rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.tab-btn:hover:not(.active) {
  background: var(--panel-soft);
  color: var(--text);
}

.tab-btn.active {
  background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

.content-area {
  background: linear-gradient(180deg, var(--panel), var(--panel-soft));
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
  padding: 18px;
  min-height: 540px;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.18s ease;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.input-group {
  margin-bottom: 14px;
  padding: 14px;
  background: linear-gradient(180deg, var(--panel-soft), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.text-small {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.55;
}

.text-large {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.2;
  word-break: break-word;
  letter-spacing: -0.01em;
}

.text-center {
  text-align: center;
}

.mt-1 {
  margin-top: 4px;
}

.mt-2 {
  margin-top: 8px;
}

.mb-2 {
  margin-bottom: 8px;
}

.outline,
.btn-small,
#btn-exp-save,
#btn-rate-add,
#btn-add-fav,
#btn-modal-close,
#btn-force-update {
  min-height: 42px;
  border-radius: 13px;
  padding: 0 12px;
  font-weight: 700;
}

.outline {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.outline:hover:not(:disabled) {
  background: var(--panel-soft);
  border-color: var(--primary);
}

#btn-exp-save,
#btn-rate-add {
  background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  color: #ffffff;
  border: 1px solid transparent;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18);
}

#btn-exp-save:hover:not(:disabled),
#btn-rate-add:hover:not(:disabled) {
  filter: brightness(1.02);
}

#btn-add-fav,
#btn-modal-close,
#btn-force-update {
  width: 100%;
}

.btn-small {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.82rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.btn-small.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.16);
}

.btn-small:disabled,
.outline:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-soft));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.list-item > div:first-child {
  min-width: 0;
  flex: 1;
}

.list-item strong,
.list-item b {
  font-weight: 800;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

.pagination span {
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 52px;
  text-align: center;
  font-weight: 700;
}

#conv-result {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 48px;
  padding: 8px 0;
}

#conv-rate-info {
  margin-top: 10px;
}

#tab-time .input-group {
  padding: 22px 16px;
}

#time-jp-date,
#time-local-date {
  font-weight: 700;
}

#time-jp-time,
#time-local-time {
  margin-top: 6px;
}

#tab-expense .input-group:first-child input[type="text"] {
  margin-top: 8px;
}

#exp-list .list-item,
#rates-list .list-item,
#fav-list .list-item,
#hist-list .list-item,
#modal-list .list-item {
  min-height: 72px;
}

#tab-settings .input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  flex-direction: column;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.06), transparent 28%),
    var(--bg);
  padding:
    calc(env(safe-area-inset-top) + 16px)
    16px
    calc(env(safe-area-inset-bottom) + 16px);
}

.modal.active {
  display: flex;
}

.modal-header {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: 0.01em;
}

#modal-search {
  margin-bottom: 12px;
}

#modal-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
}

#modal-list .list-item {
  cursor: pointer;
}

#modal-list .list-item:hover {
  border-color: var(--primary);
  background: var(--panel-strong);
}

#btn-modal-close {
  margin-top: 12px;
}

@media (max-width: 520px) {
  body {
    padding-left: 10px;
    padding-right: 10px;
  }

  .header {
    padding: 16px;
  }

  .header-title {
    font-size: 1.3rem;
  }

  .status-text {
    font-size: 0.78rem;
    min-height: 32px;
    padding: 0 10px;
  }

  .tabs-container {
    padding: 10px;
  }

  .tab-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-row:last-child {
    grid-template-columns: repeat(3, 1fr);
  }

  .tab-btn {
    font-size: 0.86rem;
    min-height: 42px;
  }

  .content-area {
    padding: 14px;
    min-height: 460px;
  }

  .input-group {
    padding: 12px;
  }

  .input-row,
  .flex-space {
    flex-direction: column;
    align-items: stretch;
  }

  .input-row > *,
  .flex-space > * {
    width: 100% !important;
    margin-right: 0 !important;
  }

  .text-large {
    font-size: 1.58rem;
  }

  .list-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .list-item > div:last-child {
    width: 100%;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }

  .pagination {
    flex-wrap: wrap;
  }
}

@media (max-width: 360px) {
  .tab-row,
  .tab-row:last-child {
    grid-template-columns: 1fr 1fr;
  }

  .text-large {
    font-size: 1.38rem;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-text {
    width: 100%;
    justify-content: center;
  }
}