:root {
  --system-red: #FF3B30;
  --system-orange: #FF9500;
  --system-green: #34C759;
  --system-blue: #007AFF;
  --system-indigo: #5856D6;
  --system-gray: #8E8E93;
  --system-gray2: #AEAEB2;
  --system-gray3: #C7C7CC;
  --system-gray4: #D1D1D6;
  --system-gray5: #E5E5EA;
  --system-gray6: #F2F2F7;
  --bg-color: #F2F2F7;
  --surface-color: #FFFFFF;
  --text-primary: #000000;
  --text-secondary: #8A8A8E;
}

* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard Variable", Pretendard, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  margin: 0;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg-color);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}

@media (min-width: 1400px) {
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    background: #e0e0e5;
  }
  .app-container {
    max-width: 1194px;
    height: 85vh;
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  }
}

/* iOS Header */
.ios-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.ios-header .header-left,
.ios-header .header-right {
  width: 140px;
  flex-shrink: 0;
}

.ios-header .header-right {
  text-align: right;
}

.ios-header .header-title {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

/* View container */
.view-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}
.has-tab-bar .view-content {
  padding-bottom: 16px;
}

/* iOS Cards */
.ios-card {
  background: var(--surface-color);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* iOS Inputs */
.ios-input-group {
  background: var(--surface-color);
  border-radius: 12px;
  overflow: hidden;
}

.ios-input {
  width: 100%;
  padding: 16px;
  border: none;
  font-size: 17px;
  background: transparent;
  outline: none;
  border-bottom: 0.5px solid var(--system-gray5);
}
.ios-input:last-child { border-bottom: none; }
.ios-input::placeholder { color: var(--text-secondary); }

/* Buttons */
.ios-btn-primary {
  width: 100%;
  background-color: var(--system-blue);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.ios-btn-primary:active { opacity: 0.7; }
.ios-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.ios-btn-secondary {
  width: 100%;
  background-color: var(--system-gray5);
  color: var(--system-blue);
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.ios-btn-text {
  color: var(--system-blue);
  font-size: 17px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--system-blue);
  color: white;
}
.badge-red { background: var(--system-red); }
.badge-green { background: var(--system-green); }

/* Season/Category tabs */
.pill-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--system-gray4);
  background: var(--surface-color);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.pill-tab.active {
  background: rgba(0, 122, 255, 0.1);
  border-color: var(--system-blue);
  color: var(--system-blue);
}

/* Week card */
.week-card {
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  border: 1px solid var(--system-gray5);
  background: var(--system-gray6);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.week-card:active { transform: scale(0.96); }
.week-card.active {
  border-color: var(--system-blue);
  background: #fff;
  box-shadow: 0 0 0 1px var(--system-blue);
}

/* Day card */
.day-card {
  flex: 1;
  border-radius: 8px;
  padding: 10px 4px 8px;
  text-align: center;
  background: var(--system-gray6);
  border: 1px solid var(--system-gray5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.2s;
  text-decoration: none;
  color: inherit;
}
.day-card:active { transform: scale(0.95); }
.day-card.hi { background: rgba(52, 199, 89, 0.1); border-color: var(--system-green); }
.day-card.lo { background: rgba(255, 59, 48, 0.1); border-color: var(--system-red); }

/* Dual bar */
.dual-bar {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--system-gray5);
  width: 100%;
}
.dual-bar .mine-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--system-blue);
  border-radius: 4px;
  z-index: 1;
}
.dual-bar .avg-marker {
  position: absolute;
  width: 3px;
  height: 14px;
  background: var(--text-secondary);
  border-radius: 2px;
  z-index: 2;
  transform: translateX(-50%);
  top: -3px;
}

/* OMR */
.ans-opt {
  flex: 1;
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--system-gray4);
  background: var(--surface-color);
  font-size: 17px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.ans-opt:active:not(.locked) { transform: scale(0.95); }
.ans-opt.picked {
  background: rgba(0, 122, 255, 0.1);
  border-color: var(--system-blue);
  color: var(--system-blue);
  font-weight: 600;
}
.ans-opt.locked { cursor: default; opacity: 0.6; }

/* Result grid */
.res-item {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.res-correct { background-color: rgba(52, 199, 89, 0.15); color: var(--system-green); }
.res-wrong { background-color: rgba(255, 59, 48, 0.15); color: var(--system-red); }
.res-null { background-color: var(--system-gray5); color: var(--system-gray); }

/* Segmented Control */
.segmented-control {
  display: flex;
  background-color: var(--system-gray5);
  border-radius: 8px;
  padding: 2px;
}
.segment {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.2s;
}
.segment.active {
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Pagination */
.pag-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--system-gray4);
  background: #fff;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.pag-btn:hover:not(:disabled) { background: var(--system-gray6); }
.pag-btn.active { background: var(--system-blue); color: #fff; border-color: var(--system-blue); }
.pag-btn:disabled { opacity: 0.3; cursor: default; }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th { border-bottom: 1px solid var(--system-gray5); padding: 10px 8px; text-align: left; font-weight: 600; }
.admin-table td { padding: 10px 8px; vertical-align: middle; border-bottom: 0.5px solid var(--system-gray6); }
.admin-table tr:hover td { background-color: var(--system-gray6); }

/* Warn box */
.warn-box {
  background: rgba(255, 149, 0, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #b25000;
  line-height: 1.5;
}

/* Status pills */
.status-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* Area selector */
.area-selector {
  flex: 1;
  border: 1px solid var(--system-gray4);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  background: var(--surface-color);
}
.area-selector.active {
  border-color: var(--system-blue);
  background: rgba(0,122,255,0.05);
}
.area-selector.active .area-name {
  color: var(--system-blue);
}

/* Helper classes */
.text-secondary { color: var(--text-secondary); }
.text-blue { color: var(--system-blue); }
.text-red { color: var(--system-red); }
.text-green { color: var(--system-green); }
.text-orange { color: var(--system-orange); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* Bottom Tab Bar */
.bottom-tab-bar {
  display: flex;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.1);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.bottom-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  text-decoration: none;
  color: var(--system-gray);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
}
.bottom-tab-item.active {
  color: var(--system-blue);
}
.bottom-tab-item .tab-icon {
  font-size: 22px;
  line-height: 1;
}

/* Tab panel visibility */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === iPad responsive === */
@media (max-width: 840px) {
  .dashboard-2col {
    grid-template-columns: 1fr !important;
  }
}

@media (pointer: coarse) {
  .ans-opt { min-height: 56px; }
  .pill-tab { padding: 8px 16px; font-size: 14px; }
  .week-card { padding: 12px 10px; }
  .pag-btn { width: 40px; height: 40px; font-size: 15px; }
  .admin-table th, .admin-table td { padding: 12px 10px; font-size: 13px; }
  .ios-header { height: 64px; }
  .segment { padding: 10px 0; font-size: 15px; }
}

@media (min-width: 841px) and (max-width: 1399px) {
  .app-container { max-width: 100%; }
}
