[hidden] {
  display: none !important;
}

#m-app,
#m-app * {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: #f4f5f7;
}

#m-app {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

#m-boot-splash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--canvas);
  z-index: 200;
}

#m-boot-splash .m-brand-mark {
  margin-bottom: 0;
}

.m-motion-fade-in {
  animation: m-fade-in var(--motion-fade) var(--ease-press) both;
}

@keyframes m-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.m-motion-rise-in {
  animation: m-rise-in var(--motion-enter) var(--ease-enter) both;
}

@keyframes m-rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.m-motion-push-in {
  animation: m-push-in var(--motion-enter) var(--ease-enter) both;
}

@keyframes m-push-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

.m-motion-pop-in {
  animation: m-pop-in var(--motion-pop) var(--ease-enter) both;
}

@keyframes m-pop-in {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: none; }
}

.m-motion-boot-in {
  animation: m-fade-in var(--motion-press-release) var(--ease-press) both;
}

.m-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  height: var(--mobile-header-height);
  padding: 0 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

.m-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--mobile-touch-size);
  height: var(--mobile-touch-size);
  flex: 0 0 var(--mobile-touch-size);
  border: 0;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--motion-press-release) var(--ease-press),
              background-color var(--motion-press-release) var(--ease-press);
}

.m-header-btn:active {
  background: var(--surface-hover);
  transform: scale(0.94);
  transition-duration: var(--motion-press);
}

.m-title {
  flex: 1;
  margin: 0;
  font-size: var(--font-size-page-title);
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color var(--motion-pop) var(--ease-press);
}

.m-actions {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.m-view {
  padding: var(--mobile-page-padding);
  padding-bottom: calc(var(--mobile-page-padding) + var(--mobile-safe-bottom));
  max-width: 100%;
  overflow-x: hidden;
}

#m-app[data-tabbar="true"] .m-view {
  padding-bottom: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom) + var(--mobile-page-padding));
}

.m-placeholder {
  padding: 40px 16px;
  text-align: center;
}

.m-placeholder-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--text-tertiary);
}

.m-placeholder h2 {
  margin: 0 0 8px;
  font-size: var(--font-size-card-title);
  font-weight: 600;
}

.m-placeholder p {
  margin: 0;
  font-size: var(--font-size-label);
  color: var(--text-secondary);
  line-height: 1.5;
}

.m-hub-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.m-grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--mobile-icon-cell);
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--motion-press-release) var(--ease-press),
              background-color var(--motion-press-release) var(--ease-press);
}

.m-grid-item:active {
  background: var(--surface-hover);
  transform: scale(0.94);
  transition-duration: var(--motion-press);
}

.m-grid-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--action-soft);
  color: var(--action);
  flex: 0 0 auto;
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

.m-grid-icon svg {
  width: 22px;
  height: 22px;
}

.m-grid-label {
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-primary);
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: color var(--motion-pop) var(--ease-press);
}

.m-auth {
  padding-top: 8px;
}

.m-auth-accounts {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.m-auth-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-primary);
}

.m-auth-account span {
  color: var(--action);
  font-size: var(--font-size-label);
}

.m-auth-brand {
  text-align: center;
  margin: 24px 0 20px;
}

.m-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--action);
  color: var(--text-inverse);
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 12px;
}

.m-auth-brand h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.m-auth-brand p {
  margin: 4px 0 0;
  font-size: var(--font-size-label);
  color: var(--text-secondary);
}

.m-auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.m-auth-tab {
  flex: 1;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--font-size-body);
  cursor: pointer;
}

.m-auth-tab.active {
  background: var(--action-soft);
  border-color: var(--action);
  color: var(--action);
  font-weight: 600;
}

.m-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.m-form-field span {
  font-size: var(--font-size-label);
  color: var(--text-secondary);
}

.m-form-field input,
.m-form-field select {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
}

.m-form-field input:focus,
.m-form-field select:focus {
  outline: none;
  border-color: var(--action);
}

.m-form-field input[type="checkbox"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
}

.m-auth-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--market-up-soft);
  color: var(--market-up);
  font-size: var(--font-size-label);
}

.m-btn-primary {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--action);
  color: var(--text-inverse);
  font-size: var(--font-size-body);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--motion-press-release) var(--ease-press),
              background-color var(--motion-press-release) var(--ease-press);
}

.m-btn-primary:active {
  background: var(--action-hover);
  transform: scale(0.98);
  transition-duration: var(--motion-press);
}

.m-btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.m-btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: m-spin 800ms linear infinite;
}

@keyframes m-spin {
  to { transform: rotate(360deg); }
}

.m-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--m-keyboard-inset);
  z-index: 60;
  display: flex;
  align-items: stretch;
  height: calc(var(--mobile-tabbar-height) + var(--mobile-safe-bottom));
  padding-bottom: var(--mobile-safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

.m-tabbar-item {
  flex: 1;
  min-width: 0;
  min-height: var(--mobile-tabbar-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--motion-press-release) var(--ease-press),
              background-color var(--motion-press-release) var(--ease-press),
              color var(--motion-pop) var(--ease-press);
}

.m-tabbar-item:active {
  background: var(--surface-hover);
  transform: scale(0.94);
  transition-duration: var(--motion-press), var(--motion-press), var(--motion-pop);
}

.m-tabbar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  transition: transform var(--motion-press-release) var(--ease-press);
}

.m-tabbar-item:active .m-tabbar-icon {
  transform: scale(0.88);
  transition-duration: var(--motion-press);
}

.m-tabbar-label {
  font-size: var(--mobile-tabbar-label-size);
  line-height: 1.2;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.m-tabbar-item.active {
  color: var(--action);
}

.m-theme-section {
  margin-bottom: 12px;
}

.m-theme-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--elevation-card);
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

.m-theme-row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--action-soft);
  color: var(--action);
  flex: 0 0 auto;
  transition: background-color var(--motion-pop) var(--ease-press),
              border-color var(--motion-pop) var(--ease-press);
}

.m-theme-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.m-theme-row-body strong {
  font-size: var(--font-size-card-title);
  font-weight: 600;
  line-height: 1.4;
}

.m-theme-row-body small {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.m-theme-switch {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.m-theme-switch[aria-checked="true"] {
  background: var(--action);
}

.m-theme-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-inverse);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.m-theme-switch[aria-checked="true"] .m-theme-switch-thumb {
  transform: translateX(20px);
}

@media (prefers-reduced-motion: reduce) {
  .m-motion-rise-in,
  .m-motion-push-in,
  .m-motion-pop-in {
    animation-name: m-fade-in;
    animation-duration: 100ms;
  }

  .m-motion-fade-in {
    animation-duration: 100ms;
  }

  .m-grid-item:active,
  .m-header-btn:active,
  .m-btn-primary:active,
  .m-tabbar-item:active {
    transform: none;
  }

  .m-tabbar-item:active .m-tabbar-icon {
    transform: none;
  }
}
