@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Space+Grotesk:wght@400;500;600&display=swap');

:root {
  --bg: #f4efe6;
  --ink: #1f1f1b;
  --muted: #6b6b60;
  --card: #ffffff;
  --accent: #1d6a47;
  --fw: #e04c3a;
  --mf: #37a64a;
  --df: #2c6be0;
  --gk: #f2c94c;
  --pitch: #2b7c3f;
  --pitch-dark: #266c37;
  --line: rgba(255, 255, 255, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  background: radial-gradient(circle at 10% 10%, #fff4e1, #f4efe6 60%);
  color: var(--ink);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.kicker {
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
}

h1 {
  font-family: 'Playfair Display', serif;
  font-size: 34px;
  margin: 0 0 8px;
}

.sub {
  margin: 0;
  color: var(--muted);
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.legend-item {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  color: #fff;
}

.legend-item.fw { background: var(--fw); }
.legend-item.mf { background: var(--mf); }
.legend-item.df { background: var(--df); }
.legend-item.gk { background: var(--gk); color: #2c2c2c; }

.app-main {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 24px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.08);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

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

.row.wrap {
  flex-wrap: wrap;
}

.row + .row {
  margin-top: 10px;
}

input[type="text"],
select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d9d4c8;
  font-family: inherit;
}

button {
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.08);
}

.primary {
  background: var(--accent);
  color: #fff;
}

.secondary {
  background: #efe8db;
  color: #2d2d27;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.pill {
  background: #f8e3b6;
  padding: 2px 6px;
  border-radius: 6px;
}

.status {
  font-size: 13px;
  color: var(--muted);
}

.player-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f7f3ea;
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid transparent;
  cursor: pointer;
}

.player.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 106, 71, 0.12);
}

.player-name {
  font-weight: 600;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 6px;
  color: #fff;
}

.tag.attend { background: #e2b84a; color: #3b2d00; }
.tag.merc { background: #32475c; }

.player button {
  background: transparent;
  border: none;
  color: #a13c2f;
  font-weight: 700;
}

.quarter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  padding: 6px 12px;
  border-radius: 999px;
  background: #eee6d8;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.pitch-wrap {
  background: #1f1f1b;
  border-radius: 24px;
  padding: 16px;
}

.pitch {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: repeating-linear-gradient(
    0deg,
    var(--pitch) 0,
    var(--pitch) 12%,
    var(--pitch-dark) 12%,
    var(--pitch-dark) 24%
  );
  border-radius: 18px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35);
  overflow: hidden;
}

.pitch::before,
.pitch::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--line);
}

.pitch::before { top: 50%; }
.pitch::after { top: 12%; }

.center-circle {
  position: absolute;
  width: 120px;
  height: 120px;
  border: 2px solid var(--line);
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.position {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.position.empty {
  background: rgba(255,255,255,0.2);
  border: 2px dashed rgba(255,255,255,0.6);
}

.position.fw { background: var(--fw); }
.position.mf { background: var(--mf); }
.position.df { background: var(--df); }
.position.gk { background: var(--gk); color: #2c2c2c; }

.position.selected {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.8);
  transform: translate(-50%, -50%) scale(1.06);
}

@media (max-width: 980px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

.position {
  padding: 4px;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-player {
  color: #a13c2f;
  font-size: 12px;
}

button:disabled,
select:disabled,
input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Mobile-first optimization */
.app {
  max-width: 560px;
  padding: 12px 10px 24px;
}

.app-header {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.22em;
}

h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.sub {
  font-size: 13px;
  line-height: 1.35;
}

.app-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.panel {
  gap: 12px;
}

.panel.right {
  order: 1;
}

.panel.left {
  order: 2;
}

.card {
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.card h2 {
  font-size: 16px;
  margin-bottom: 10px;
}

.row {
  width: 100%;
  flex-wrap: wrap;
  gap: 8px;
}

.row > * {
  flex: 1 1 auto;
  min-width: 0;
}

input[type="file"],
input[type="text"],
select,
button {
  width: 100%;
  min-height: 44px;
  font-size: 14px;
}

.legend {
  width: 100%;
}

.legend-item {
  font-size: 11px;
  padding: 5px 9px;
}

.tabs {
  width: 100%;
  display: grid !important;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.tab {
  min-height: 34px;
  width: 100%;
  padding: 5px 4px;
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-list {
  max-height: 260px;
}

.player {
  min-height: 44px;
  border-radius: 10px;
}

.pitch-wrap {
  padding: 10px;
  border-radius: 16px;
}

.pitch {
  aspect-ratio: 3 / 4.3;
  border-radius: 12px;
}

.position {
  width: 52px;
  height: 52px;
  font-size: 11px;
}

@media (min-width: 900px) {
  .app {
    max-width: 1200px;
    padding: 26px 20px 36px;
  }

  .app-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
  }

  h1 {
    font-size: 34px;
  }

  .app-main {
    grid-template-columns: 1fr 1.35fr;
    gap: 20px;
  }

  .panel.right {
    order: 2;
  }

  .panel.left {
    order: 1;
  }

  .row > * {
    flex: 0 1 auto;
  }

  input[type="file"],
  input[type="text"],
  select,
  button {
    width: auto;
    min-height: 38px;
  }

  .pitch {
    aspect-ratio: 3 / 4;
  }

  .position {
    width: 58px;
    height: 58px;
    font-size: 12px;
  }
}

/* Force mobile view on all screen sizes */
.app {
  max-width: 560px !important;
  padding: 12px 10px 24px !important;
}

.app-header {
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  gap: 10px !important;
  margin-bottom: 14px !important;
}

h1 {
  font-size: 24px !important;
}

.app-main {
  grid-template-columns: 1fr !important;
  gap: 12px !important;
}

.panel.right {
  order: 1 !important;
}

.panel.left {
  order: 2 !important;
}

.card {
  border-radius: 14px !important;
  padding: 12px !important;
}

.row {
  flex-wrap: wrap !important;
}

.row > * {
  flex: 1 1 100% !important;
}

input[type="file"],
input[type="text"],
select,
button {
  width: 100% !important;
  min-height: 44px !important;
}

.pitch {
  aspect-ratio: 3 / 4.3 !important;
}

.position {
  width: 52px !important;
  height: 52px !important;
  font-size: 11px !important;
}

/* NanumSquare global font */
@font-face {
  font-family: 'NanumSquare';
  src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2107@1.1/NanumSquareRegular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: 'NanumSquare';
  src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2107@1.1/NanumSquareBold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
}

* {
  font-family: 'NanumSquare', sans-serif !important;
}

.status-box {
  display: inline-block;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f4efe4;
  border: 1px solid #ded5c6;
  color: #5e5e55;
  font-size: 12px;
  line-height: 1.35;
}

.status-box.error {
  border-color: #e2b7b0;
  background: #fff1ee;
  color: #b93d2d;
}

/* Layout tune: linear flow order and compact quarter controls */
.flow-main {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
}

.flow-main > .card,
.flow-main > .pitch-wrap {
  width: 100%;
}

.flow-main .card {
  padding: 12px !important;
  border-radius: 14px !important;
}

.flow-main .row {
  gap: 8px;
}

.flow-main .row > * {
  flex: 1 1 auto !important;
}

#ocrBtn,
#addMerc {
  width: auto !important;
  min-width: 110px;
}

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

.quarter-header h2 {
  margin: 0;
}

#addQuarter {
  width: auto !important;
  min-height: 34px !important;
  min-width: 88px;
  padding: 6px 10px !important;
  flex: 0 0 auto !important;
}

.quarter-card .tabs {
  margin-bottom: 8px;
}

.controls .row.wrap {
  align-items: flex-end;
}

.controls label {
  flex: 1 1 220px;
}

#lockToggle,
#captureBtn,
#copyBtn {
  width: auto !important;
  min-width: 84px;
  flex: 0 0 auto !important;
}

.pitch-wrap {
  margin-top: 0;
}

/* UI cleanup request: legend near pitch + 70% field transparency */
.legend-near-pitch {
  margin-top: -2px;
  margin-bottom: 2px;
}

.pitch {
  background: repeating-linear-gradient(
    0deg,
    rgba(43, 124, 63, 0.7) 0,
    rgba(43, 124, 63, 0.7) 12%,
    rgba(38, 108, 55, 0.7) 12%,
    rgba(38, 108, 55, 0.7) 24%
  ) !important;
}

.edit-player {
  background: transparent;
  border: none;
  color: #24528f;
  font-weight: 700;
  font-size: 12px;
}
